The kth great number

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others)
Total Submission(s): 5049    Accepted Submission(s): 2069

Problem Description
Xiao Ming and Xiao Bao are playing a simple Numbers game. In a round Xiao Ming can choose to write down a number, or ask Xiao Bao what the kth great number is. Because the number written by Xiao Ming is too much, Xiao Bao is feeling giddy. Now, try to help Xiao Bao.
 
Input
There are several test cases. For each test case, the first line of input contains two positive integer n, k. Then n lines follow. If Xiao Ming choose to write down a number, there will be an " I" followed by a number that Xiao Ming will write down. If Xiao Ming choose to ask Xiao Bao, there will be a "Q", then you need to output the kth great number. 
 
Output
The output consists of one integer representing the largest number of islands that all lie on one line. 
 
Sample Input
8 3
I 1
I 2
I 3
Q
I 5
Q
I 4
Q
 
Sample Output
1
2
3

Hint

Xiao Ming won't ask Xiao Bao the kth great number when the number of the written number is smaller than k. (1=<k<=n<=1000000).

 
Source
 
Recommend
lcy
 
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<queue>
  5. #include<algorithm>
  6. #include<vector>
  7.  
  8. using namespace std;
  9.  
  10. int n,k;
  11. priority_queue<int,vector<int>,greater<int> >q;
  12.  
  13. int main(){
  14.  
  15. //freopen("input.txt","r",stdin);
  16.  
  17. char op[];
  18. int x;
  19. while(~scanf("%d%d",&n,&k)){
  20. while(!q.empty())
  21. q.pop();
  22. for(int i=;i<k;i++){
  23. scanf("%s%d",op,&x);
  24. q.push(x);
  25. }
  26. for(int i=k;i<n;i++){
  27. scanf("%s",op);
  28. if(op[]=='Q')
  29. printf("%d\n",q.top());
  30. else{
  31. scanf("%d",&x);
  32. if(x>q.top()){
  33. q.pop();
  34. q.push(x);
  35. }
  36. }
  37. }
  38. }
  39. return ;
  40. }

HDU 4006 The kth great number (优先队列)的更多相关文章

  1. hdu 4006 The kth great number (优先队列)

    /********************************************************** 题目: The kth great number(HDU 4006) 链接: h ...

  2. HDU 4006 The kth great number 优先队列、平衡树模板题(SBT)

    The kth great number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Oth ...

  3. hdu 4006 The kth great number(优先队列)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4006 题目大意: 第一行 输入 n k,后有 n 行,对于每一行有两种状态 ,①“I x” : 插入 ...

  4. HDU - 4006 The kth great number multiset应用(找第k大值)

    The kth great number Xiao Ming and Xiao Bao are playing a simple Numbers game. In a round Xiao Ming ...

  5. HDU 4006 The kth great number(multiset(或者)优先队列)

    题目 询问第K大的数 //这是我最初的想法,用multiset,AC了——好吧,也许是数据弱也有可能 //multiset运用——不去重,边插入边排序 //iterator的运用,插入的时候,如果是相 ...

  6. HDU 4006 The kth great number【优先队列】

    题意:输入n行,k,如果一行以I开头,那么插入x,如果以Q开头,则输出第k大的数 用优先队列来做,将队列的大小维护在k这么大,然后每次取队首元素就可以了 另外这个维护队列只有k个元素的时候需要注意一下 ...

  7. hdu 4006 The kth great number

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4006 思路:利用优先队列的性质,将数据存入后会自动对数据进行排序 #include<stdlib ...

  8. HDU 4006 The kth great number AVL解

    提供动态更新数据.第实时QK大量的值什么? 使用AVL统计数据结构做,比较先进的数据结构的内容. 不知道给出的数据为准值是否有反复.下面的程序是因为我能够处理重复数据出现的情况下,. 了repeat的 ...

  9. hdoj 4006 The kth great number【优先队列】

    The kth great number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Oth ...

随机推荐

  1. Hadoop2.2.0安装配置手册!完全分布式Hadoop集群搭建过程~(心血之作啊~~)

    http://blog.csdn.net/licongcong_0224/article/details/12972889 历时一周多,终于搭建好最新版本hadoop2.2集群,期间遇到各种问题,作为 ...

  2. unity3d shader 学习

    [浅墨Unity3D Shader编程] 着色器参考 [Unity Shaders]

  3. "Ext 4.1 Grid 'el.dom' 为空或不是对象"问题的解决

    我在使用Ext 4.1 做Grid,IE下冒出这么个错误,导致表格完全显示不出来,换另外一个IE浏览器,有没有问题,呵呵,百思不得其解啊... 后来得出答案,即在grid相关代码周围套上Ext.onR ...

  4. ESXI 6.5 从载到安装

    下载ESXI 访问官网 https://www.vmware.com 到download,选择vsphere 下载esxi https://my.vmware.com/en/group/vmware/ ...

  5. WIN10系统右击开始菜单没有属性选项怎么办

    修复方法一:1.按下"WIN+R"输入:regedit回车,进入注册表编辑器:2.在注册表左侧依次打开:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ ...

  6. C#.NET常见问题(FAQ)-public private protectd internal有什么区别

    首先要区分public和private,这两个修饰符是最常用的.Public就是对外公开的,private就是对外不公开的(类内部可以使用),比如下面我定义一个类的实例,自动补全代码中只有public ...

  7. intel vt

    EPT和VPID技术是内存虚拟化技术, 是页表扩充技术Extended Page Table (EPT) 的缩写, 是VT-x技术的一部分. 内存虚拟化的主要任务是实现地址空间的虚拟化,内存虚拟化是通 ...

  8. Hibernate的配置中,c3p0连接池相关配置

    一.配置c3p0 1.导入 hibernate-c3po连接池包,Maven地址是:http://mvnrepository.com/artifact/org.hibernate/hibernate- ...

  9. Pause Web Sessions

    To pause specific sessions, add rules using FiddlerScript to the OnBeforeRequest function (except wh ...

  10. 字符串问题简述与两个基本问题的Java实现——判断二叉树拓扑结构关系与变形词

    转载请注明原文地址:http://www.cnblogs.com/ygj0930/p/6851631.html  (解题金句:其他问题字符串化,然后调用String类封装方法解决问题: 字符串问题数组 ...