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(优先队列)的更多相关文章

  1. CSU1306:Manor(优先队列)

    Description Bob有n个正整数,他将这n个整数根据大小划分成两部分.对于小于等于k的整数放在集合A中,其余的放在集合B中.每次他从集合B中取出一个最大的值,将其变成0放入A集合中.然后将A ...

  2. scau 2015寒假训练

    并不是很正规的.每个人自愿参与自愿退出,马哥找题(马哥超nice么么哒). 放假第一周与放假结束前一周 2015-01-26 http://acm.hust.edu.cn/vjudge/contest ...

  3. URAL 1306 Sequence Median(优先队列)

    题意:求一串数字里的中位数.内存为1M.每个数范围是0到2的31次方-1. 思路:很容易想到把数字全部读入,然后排序,但是会超内存.用计数排序但是数又太大.由于我们只需要第n/2.n/2+1大(n为偶 ...

  4. CSU 1726: 你经历过绝望吗?两次!(bfs+优先队列)

    传送门: http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1726 1726: 你经历过绝望吗?两次! Submit Page    Summar ...

  5. csu1306: Manor

    http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1306 解题思路:唬人的水题,只要按照他的意思打,就能过,不过,数组最好开大点.用到优先队列,也可以 ...

  6. math --- CSU 1554: SG Value

    SG Value Problem's Link:   http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1554 Mean: 一个可重集合,初始为空,每 ...

  7. ural 1306. Sequence Median

    1306. Sequence Median Time limit: 1.0 secondMemory limit: 1 MBLanguage limit: C, C++, Pascal Given a ...

  8. 2013 CSU校队选拔赛(1) 部分题解

    A: Decimal Time Limit: 1 Sec   Memory Limit: 128 MB Submit: 99   Solved: 10 [ Submit][ Status][ Web ...

  9. CSU 1554 SG Value —— 思维

    题目链接:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1554 Description The SG value of a set (mult ...

随机推荐

  1. JAVA基础之理解JNI原理

    JNI是JAVA标准平台中的一个重要功能,它弥补了JAVA的与平台无关这一重大优点的不足,在JAVA实现跨平台的同时,也能与其它语言(如C.C++)的动态库进行交互,给其它语言发挥优势的机会. 有了J ...

  2. Android混淆打包配置总结

    Android打包失败出现Proguard returned with error code 1. See console的错误 这个问题是由于代码混淆引起的,找不到引用包. 只需在你的proguar ...

  3. ActiveMQ(5.10.0) - Spring Support

    Maven Dependency: <dependencies> <dependency> <groupId>org.apache.activemq</gro ...

  4. over Oracle

    QL code: sql over的作用及用法RANK ( ) OVER ( [query_partition_clause] order_by_clause )DENSE_RANK ( ) OVER ...

  5. WebAPI GET和POST请求的几种方式

    GET请求 1.无参数get请求 一般get请求有两种写法,一种是$.get()   一种是$.ajax({type:"get"}),我个人比较喜欢用后者. 下面例子主要是get无 ...

  6. CDH离线安装之安装包下载地址

    cloudermanager安装包地址:http://archive.cloudera.com/cm5/cm/5/cloudera-manager-el6-cm5.3.0_x86_64.tar.gz, ...

  7. 利用图层的mask属性裁剪图形

    需求如上图. 代码如下 //充值 UIButton *rechargeButton = [[UIButton alloc] initWithFrame:CGRectMake(, , , )]; [re ...

  8. C# WinForm打开IE浏览器并访问网址

    C# WinForm 打开浏览器并访问网址代码: System.Diagnostics.Process.Start("iexplore.exe", "http://kel ...

  9. js画了一个椭圆

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  10. mongoDB知识总结

    官方说明文档:https://docs.mongodb.com/manual/mongo/ 1 NoSQL 简介 NoSQL,全称是”Not Only Sql”,指的是非关系型的数据库(相对于关系型数 ...