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
 
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
#include<vector> using namespace std; int n,k;
priority_queue<int,vector<int>,greater<int> >q; int main(){ //freopen("input.txt","r",stdin); char op[];
int x;
while(~scanf("%d%d",&n,&k)){
while(!q.empty())
q.pop();
for(int i=;i<k;i++){
scanf("%s%d",op,&x);
q.push(x);
}
for(int i=k;i<n;i++){
scanf("%s",op);
if(op[]=='Q')
printf("%d\n",q.top());
else{
scanf("%d",&x);
if(x>q.top()){
q.pop();
q.push(x);
}
}
}
}
return ;
}

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. PHP 自定义方法实现数组合并

    在PHP中提供了强大的数组功能,对于数组的合并也提供了两个方法:array_merge 和 array_merge_recursive 但对于我们千变万化的业务来说这些内置的方法并不完全能满足我们的要 ...

  2. linux 安装elasticsearch 可能遇到的问题

    1.can not run elasticsearch as root 切换到非root用户 因为安全问题elasticsearch 不让用root用户直接运行,所以要创建新用户 第一步:liunx创 ...

  3. 【代码片段】如何使用CSS来快速定义多彩光标

    对于web开发中,我们经常都看得到需要输入内容的组件和元素,比如,textarea,或者可编辑的DIV(contenteditable) ,如果你也曾思考过使用相关方式修改一下光标颜色的,那么这篇技术 ...

  4. Android Handler 消息处理使用

    本文内容 环境 演示 Handler 消息处理 参考资料 Handler 有两个主要作用或者说是步骤:发送消息和处理消息.在新启动的线程中发送消息,在主线程中获取.并处理消息.Android 平台只允 ...

  5. Bridging and Bonding with CentOS 6.5

    eth0和eth1要做bond,然后kvm虚拟机通过bridge与外界通信. 那么就要在bond上做bridge.配置文件例如以下,实測这样配置,能够从kvm虚拟机ping通外界拓扑. ifcfg-e ...

  6. Server Performance Advisor (SPA) 3.0

    http://blogs.technet.com/b/windows-server-china-blog/archive/2013/03/26/server-performance-advisor-s ...

  7. 002-Go通过ioutil 读写文件

    1.读取文件内容 package main import( "io/ioutil" "fmt" ) func main(){ b,err := ioutil.R ...

  8. vue重要特性

    重要特性 自定义input组件 动态组件 递归组件 slot 作用域slot 异步组件 内联模板 子组件索引 进阶 自定义指令 状态管理vuex 单文件组件 生产部署 路由 xxx

  9. Audition CC2019 MME设备内部错误怎么解决!

    安装完了AA2019,没有想到像昨天安装系统那么不顺利... 当然出现问题的原因是因为我安装了win10 并且我禁用了麦克风的所有应用权限. 设置里面搜索 麦克风 权限 Ok工作啦, 好开森~     ...

  10. JavaWeb应用项目中文乱码的解决

     转载请注明原文地址:http://www.cnblogs.com/ygj0930/p/6383542.html 在把web项目成功部署到云主机后,通过浏览器成功地访问到了你的网站,却发现页面里本该由 ...