hdu杭电4006 The kth great number【优先队列】
来源:互联网 发布:淘宝专业打假 编辑:程序博客网 时间:2024/05/16 08:59
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 3I 1I 2I 3QI 5QI 4Q
Sample Output
123HintXiao 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).
//一开始被getchar()害惨了
#include<cstdio> #include<queue>#include<iostream>using namespace std;int main(){int n,k;int temp;char ch;while(~scanf("%d%d",&n,&k)){//getchar();priority_queue<int,vector<int>,greater<int> >q;int num=0;while(n--){cin>>ch;//getchar();if(ch=='I'){if(num<k){scanf("%d",&temp);//getchar();++num;q.push(temp);}else{scanf("%d",&temp);//getchar();if(temp>q.top()){q.pop();q.push(temp);}}}else if(ch=='Q'){printf("%d\n",q.top());}}}return 0;}
0 0
- hdu杭电4006 The kth great number【优先队列】
- 杭电4006 The kth great number(优先队列)
- 杭电 4006 The kth great number(优先队列)
- 杭电-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 (优先队列)
- HDU5317.RGCDQ
- c++ 11 声明
- Linked List Cycle
- iOS9 CASpringAnimation 弹簧动画详解
- Ubuntu循环登录问题解决方案
- hdu杭电4006 The kth great number【优先队列】
- 解决Android端升级安装后自动打开的问题
- 实现文字渐变的效果
- Linux find 用法示例
- 软件测试方法和测试流程
- hdoj 1873 看病要排队 [STL 优先队列]
- 每个程序员需掌握的20个代码命名小贴士
- S3C2440学习_开篇_1
- oracle常见问题:varchar2 char的区别