hdoj 4006 The kth great number
来源:互联网 发布:mac磁盘恢复到单一分区 编辑:程序博客网 时间:2024/05/16 23:41
The kth great number
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others)
Total Submission(s): 8622 Accepted Submission(s): 3399
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)./*这个题比较容易想到优先队列,只需 简单进出即可,但要保持数量!(关键) */ #include<stdio.h>#include<string.h>#include<iostream>#include<queue> #include<algorithm>using namespace std;int main(){ int n,m; while(scanf("%d %d",&n,&m)!=EOF) { priority_queue<int, vector<int>, greater<int> >q; //建立优先队列,从小到大 int a,b; char s[10]; while(n--) { scanf("%s",s); if(s[0]=='I') { scanf("%d",&a); q.push(a); if(q.size()>m)//当队列长队超过m时,弹出队首,使队保持m个元素 { q.pop() ; } } else if(s[0]=='Q') { b=q.top(); printf("%d",b); printf("\n"); } } } return 0;}
0 0
- hdoj 4006 The kth great number
- HDOJ 4006 The kth great number
- HDOJ 4006 The kth great number
- hdoj 4006 The kth great number
- hdoj-4006-The kth great number
- HDOJ 4006 The kth great number
- hdoj 4006 The kth great number 【栈】
- hdoj 4006The kth great number(优先级队列)
- HDOJ 4006The kth great number 解题报告
- HDOJ 4006 The kth great number(优先队列)
- HDOJ 4006 - The kth great number 优先队列水
- hdoj 4006 The kth great number(优先队列)
- HDOJ 4006 The kth great number(优先队列)
- hdoj 4006 The kth great number【优先队列】
- HDOJ 4006 The kth great number(优先队列)
- The kth great number
- The kth great number
- The kth great number
- poj 1844 数学(1+/- ... k)
- HDU5001 Walk
- Android 通过广播接听Home键
- 03-树1. 二分法求多项式单根(20) Python
- postgresql继承方式实现分区
- hdoj 4006 The kth great number
- Number of Digit One
- 收藏网址
- symbolicatecrash工具
- Linux下静态库_库的基本概念;如何生成静态库动态库;nm查看库中包含那些函数、ar生成静态库,查看库中包含那些.o文件、ldd查看程序依赖的.so文件;gcc/g++与库相关的参数-L,-l,-f
- CURL POST请求上传图片
- 判断以逗号分隔的字符串中是否包含某个数
- 判断大小端
- 线程Looper+Handler+Thread学习