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

  1. 5 100 40 20
  2. 1000 250 300 10 25
  3. 10
  4. 1
  5. 2
  6. 3
  7. 4
  8. 5
  9. 6
  10. 7
  11. 8
  12. 9
  13. 10
  14. 4 100 10 10
  15. 105 150 25 75
  16. 4
  17. 1
  18. 2
  19. 3
  20. 4

Sample Output

  1. 3
  2. 2
  3. 2
  4. 3
  5. 3
  6. 3
  7. 3
  8. 3
  9. 3
  10. 3
  11. 2
  12. 1
  13. 0
  14. 1

  15. 【题解】:
    优先队列
    code】:
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <algorithm>
  5. #include <queue>
  6.  
  7. using namespace std;
  8.  
  9. int B_cnt,a,i;
  10.  
  11. struct Nod
  12. {
  13. int x;
  14. int id;
  15. }nd;
  16.  
  17. priority_queue<Nod> p_q;
  18.  
  19. bool operator<(Nod c,Nod b)
  20. {
  21. return c.x+(i-c.id)*a<b.x+(i-b.id)*a;
  22. /*这种更好
  23. if(c.id!=b.id) return c.id>b.id;
  24. return c.x<b.x;
  25. */
  26. }
  27.  
  28. int main()
  29. {
  30. int n,k,b,q;
  31. while(~scanf("%d%d%d%d",&n,&k,&a,&b))
  32. {
  33. B_cnt=;
  34. while(!p_q.empty()){p_q.pop();}
  35. int x;
  36. for(i=;i<n;i++)
  37. {
  38. scanf("%d",&x);
  39. if(x>k) B_cnt++;
  40. else
  41. {
  42. nd.id = ;
  43. nd.x = x;
  44. p_q.push(nd);
  45. }
  46. }
  47. scanf("%d",&q);
  48. int maks=;
  49. int qu[];
  50. for(i=;i<=q;i++)
  51. {
  52. scanf("%d",&qu[i]);
  53. if(maks<qu[i]) maks=qu[i];
  54. }
  55.  
  56. int arr[];
  57. arr[]=B_cnt;
  58.  
  59. for(i=;i<=maks;i++)
  60. {
  61. arr[i]=B_cnt;
  62. if(B_cnt>)
  63. {
  64. B_cnt--;
  65. nd.id = i - ;
  66. nd.x = ;
  67. p_q.push(nd);
  68. }
  69. while(!p_q.empty())
  70. {
  71. Nod temp = p_q.top();
  72. if(temp.x+(i-temp.id)*a<=k) break;
  73. p_q.pop();
  74. B_cnt++;
  75. }
  76. }
  77. for(i=;i<=q;i++)
  78. {
  79. printf("%d\n",arr[qu[i]]);
  80. }
  81. }
  82. return ;
  83. }

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. 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 ...

  2. 【TOMCAT】Tomcat gzip压缩传输数据

    概述 由于我们项目的三维模型文件非常大,为了提高传输速度,在服务端对其做zip压缩处理非常有必要,能够极大的提高传输速度. 配置 首先需要修改web.xml中请求的数据文件的mime类型的mappin ...

  3. HDOJ2026首字母变大写

    首字母变大写 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  4. python - 图例显示中文

    # -*- coding: utf-8 -*- """ Created on Mon Nov 30 13:24:00 2015 @author: jx_luo " ...

  5. jFinal中报对应模型不存在的错误(The Table mapping of model: demo.User not exists)

    jFinal中报对应模型不存在的错误(The Table mapping of model: demo.User not exists) 贴出错误: java.lang.RuntimeExceptio ...

  6. (转)Ehcache作为分布式缓存的研究

    ehcache支持两种拓扑结构,一种是Distributed Caching,另一种是Replicated Caching Distributed Caching 这和一般意义上的分布式缓存非常类似, ...

  7. UvaLive7362 Fare(欧拉函数)

    题意:求1~n的素因子之和. 分析:欧拉函数 #include<cstdio> #include<cstring> #include<cctype> #includ ...

  8. 30分钟搭建一个小型网站框架(python django)

    最近因为要做一个小型的网站,需求很简单有点像公司内部的管理网站,和室友一起倒腾,发现了一些坑.我自己之前没有接触过python 但是发现真的非常好上手. 我们没人会前端,所以最怕修改网页,一开始选择了 ...

  9. MQ队列

    显示队列名dspmq 打开队列 runmqsc QMSAA 200-远程队列 dis qr(*) 显示所有队列 dis qr(saa_to_cips) all 显示队列参数 20-本地队列 查看队列深 ...

  10. C++对象的JSON序列化与反序列化探索续-复杂对象的序列化与反序列化

    本文是基本上一篇博文进行改进而成,上一篇请见: C++对象的JSON序列化与反序列化探索 此处就不多说了,直接上代码. 1. 序列化基类 #pragma once #include <strin ...