HDU 4006 The kth great number(优先队列)
来源:互联网 发布:apache ab 参数说明 编辑:程序博客网 时间:2024/05/20 18:47
第K大的数,我也是醉了,刚开始不能理解第k大的数,一直认为1,2,3这几个三大的数是3啊。真是愚蠢之极啊!!!3最大,3是第一大。
然后用一般方法会超时,所以用priority_queue<int, vector<int>, greater<int> > pq;优先队列,更改了排序为逆序用greater<int>,默认正序排序less<int>
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 3I 1I 2I 3QI 5QI 4Q
Sample Output
123
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).
#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <stack>#include <queue>#include <algorithm>#include <set>using namespace std;#define LOCAL#define INF 0x3f3f3f3f#define MAX_N 10000priority_queue<int, vector<int>, greater<int> > pq;int main(){#ifdef LOCALfreopen("b:\\data.in.txt", "r", stdin);#endif int n, k, in; char c; while(~scanf("%d%d", &n, &k)) { while(!pq.empty()) pq.pop(); for(int i = 0; i < k; i++) { cin >> c; scanf("%d", &in); pq.push(in); } int cnt = n - k; while(cnt--) { int kth = pq.top();// cout << pq.top() << endl; cin >> c; if(c == 'I') { scanf("%d", &in); if(in > kth) { pq.pop(); pq.push(in); } } else { printf("%d\n", kth); } } } return 0;}
0 0
- hdu 4006 The kth great number(使用优先队列)
- HDU 4006 The kth great number(优先队列、堆实现)
- HDU 4006 The kth great number (堆实现优先队列)
- HDU 4006 The kth great number(优先队列)
- HDU 4006 The kth great number(优先队列)
- hdu 4006 The kth great number(优先队列)
- hdu 4006 The kth great number 优先队列
- HDU-#4006 The kth great number(优先队列)
- HDU 4006 The kth great number【优先队列】
- hdu 4006 The kth great number(优先队列)
- HDU 4006 The kth great number(优先队列)
- hdu杭电4006 The kth great number【优先队列】
- hdu 4006 The kth great number(线段树 || 优先队列)
- HDU 4006 The kth great number(优先队列)
- HDU 4006 The kth great number (优先队列)
- 【HDU 4006】The kth great number(优先队列)
- HDU 4006 The kth great number (优先队列)
- 【HDU】-4006-The kth great number(优先队列,好)
- boost for android
- 存储系统-半导体存储原理及芯片
- 通过mac电脑的下载服务器的日志与日志筛选
- windows核心编程 如何等待超过64 kernal object
- 获取控件高度—最简单也最难——如何获取到Android控件的高度
- HDU 4006 The kth great number(优先队列)
- Linux系统mysql密码和远程访问设置
- 新增的input表单
- matlab生成dll
- 返回顶部
- StringTokenizer截取字符串
- 微信企业号发送消息missing agentid 错误的原因
- 【CSS3】 结构性伪类选择器—root
- Java 多线程 并发编程