csu 1306 Manor(优先队列)
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1306
1306: Manor
Time Limit: 1 Sec Memory Limit: 128 MB Submit: 125 Solved: 35 [Submit][Status][Web Board]
Description
Bob有n个正整数,他将这n个整数根据大小划分成两部分。对于小于等于k的整数放在集合A中,其余的放在集合B中。每次他从集合B中取出一个最大的值,将其变成0放入A集合中。然后将A集合中所有的元素都增加a,如果此时A中元素大于k,那么要将该元素放入B中,同时将B集合中剩余的元素都增加b。Bob现在想知道经过m次操作后,B集合中元素的个数。
Input
有多组测试数据。
每组测试数据的第一行为4个整数n,k,a,b,n<=100000,k<=10^3,a,b<=100, 含义同上。接下的来的一行有n个数,表示这n个数的初始值(初始值小于等于200)。接下来的一行有一个整数q(q<=100),表示有q个询问。接下来有q行,每行一个正整数m(m<=200),表示第m次操作。
Output
对于每一个询问m,输出第m次操作前集合B中元素的个数。
Sample Input
- 5 100 40 20
- 1000 250 300 10 25
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 4 100 10 10
- 105 150 25 75
- 4
- 1
- 2
- 3
- 4
Sample Output
- 3
- 2
- 2
- 3
- 3
- 3
- 3
- 3
- 3
- 3
- 2
- 1
- 0
- 1
【题解】:
优先队列
【code】:
- #include <iostream>
- #include <stdio.h>
- #include <string.h>
- #include <algorithm>
- #include <queue>
- using namespace std;
- int B_cnt,a,i;
- struct Nod
- {
- int x;
- int id;
- }nd;
- priority_queue<Nod> p_q;
- bool operator<(Nod c,Nod b)
- {
- return c.x+(i-c.id)*a<b.x+(i-b.id)*a;
- /*这种更好
- if(c.id!=b.id) return c.id>b.id;
- return c.x<b.x;
- */
- }
- int main()
- {
- int n,k,b,q;
- while(~scanf("%d%d%d%d",&n,&k,&a,&b))
- {
- B_cnt=;
- while(!p_q.empty()){p_q.pop();}
- int x;
- for(i=;i<n;i++)
- {
- scanf("%d",&x);
- if(x>k) B_cnt++;
- else
- {
- nd.id = ;
- nd.x = x;
- p_q.push(nd);
- }
- }
- scanf("%d",&q);
- int maks=;
- int qu[];
- for(i=;i<=q;i++)
- {
- scanf("%d",&qu[i]);
- if(maks<qu[i]) maks=qu[i];
- }
- int arr[];
- arr[]=B_cnt;
- for(i=;i<=maks;i++)
- {
- arr[i]=B_cnt;
- if(B_cnt>)
- {
- B_cnt--;
- nd.id = i - ;
- nd.x = ;
- p_q.push(nd);
- }
- while(!p_q.empty())
- {
- Nod temp = p_q.top();
- if(temp.x+(i-temp.id)*a<=k) break;
- p_q.pop();
- B_cnt++;
- }
- }
- for(i=;i<=q;i++)
- {
- printf("%d\n",arr[qu[i]]);
- }
- }
- return ;
- }
csu 1306 Manor(优先队列)的更多相关文章
- CSU1306:Manor(优先队列)
Description Bob有n个正整数,他将这n个整数根据大小划分成两部分.对于小于等于k的整数放在集合A中,其余的放在集合B中.每次他从集合B中取出一个最大的值,将其变成0放入A集合中.然后将A ...
- scau 2015寒假训练
并不是很正规的.每个人自愿参与自愿退出,马哥找题(马哥超nice么么哒). 放假第一周与放假结束前一周 2015-01-26 http://acm.hust.edu.cn/vjudge/contest ...
- URAL 1306 Sequence Median(优先队列)
题意:求一串数字里的中位数.内存为1M.每个数范围是0到2的31次方-1. 思路:很容易想到把数字全部读入,然后排序,但是会超内存.用计数排序但是数又太大.由于我们只需要第n/2.n/2+1大(n为偶 ...
- CSU 1726: 你经历过绝望吗?两次!(bfs+优先队列)
传送门: http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1726 1726: 你经历过绝望吗?两次! Submit Page Summar ...
- csu1306: Manor
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1306 解题思路:唬人的水题,只要按照他的意思打,就能过,不过,数组最好开大点.用到优先队列,也可以 ...
- math --- CSU 1554: SG Value
SG Value Problem's Link: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1554 Mean: 一个可重集合,初始为空,每 ...
- ural 1306. Sequence Median
1306. Sequence Median Time limit: 1.0 secondMemory limit: 1 MBLanguage limit: C, C++, Pascal Given a ...
- 2013 CSU校队选拔赛(1) 部分题解
A: Decimal Time Limit: 1 Sec Memory Limit: 128 MB Submit: 99 Solved: 10 [ Submit][ Status][ Web ...
- CSU 1554 SG Value —— 思维
题目链接:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1554 Description The SG value of a set (mult ...
随机推荐
- MyBatis(3.2.3) - Configuring MyBatis using XML, Environment
The key component of MyBatis is SqlSessionFactory from which we get SqlSession and execute the mappe ...
- 【TOMCAT】Tomcat gzip压缩传输数据
概述 由于我们项目的三维模型文件非常大,为了提高传输速度,在服务端对其做zip压缩处理非常有必要,能够极大的提高传输速度. 配置 首先需要修改web.xml中请求的数据文件的mime类型的mappin ...
- HDOJ2026首字母变大写
首字母变大写 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- python - 图例显示中文
# -*- coding: utf-8 -*- """ Created on Mon Nov 30 13:24:00 2015 @author: jx_luo " ...
- jFinal中报对应模型不存在的错误(The Table mapping of model: demo.User not exists)
jFinal中报对应模型不存在的错误(The Table mapping of model: demo.User not exists) 贴出错误: java.lang.RuntimeExceptio ...
- (转)Ehcache作为分布式缓存的研究
ehcache支持两种拓扑结构,一种是Distributed Caching,另一种是Replicated Caching Distributed Caching 这和一般意义上的分布式缓存非常类似, ...
- UvaLive7362 Fare(欧拉函数)
题意:求1~n的素因子之和. 分析:欧拉函数 #include<cstdio> #include<cstring> #include<cctype> #includ ...
- 30分钟搭建一个小型网站框架(python django)
最近因为要做一个小型的网站,需求很简单有点像公司内部的管理网站,和室友一起倒腾,发现了一些坑.我自己之前没有接触过python 但是发现真的非常好上手. 我们没人会前端,所以最怕修改网页,一开始选择了 ...
- MQ队列
显示队列名dspmq 打开队列 runmqsc QMSAA 200-远程队列 dis qr(*) 显示所有队列 dis qr(saa_to_cips) all 显示队列参数 20-本地队列 查看队列深 ...
- C++对象的JSON序列化与反序列化探索续-复杂对象的序列化与反序列化
本文是基本上一篇博文进行改进而成,上一篇请见: C++对象的JSON序列化与反序列化探索 此处就不多说了,直接上代码. 1. 序列化基类 #pragma once #include <strin ...