hdu 4006 第K大的数(优先队列)
2015-09-24 20:05
260 查看
N次操作 I是插入一个数 Q是输出第K大的数
Sample Input
8 3 //n k
I 1
I 2
I 3
Q
I 5
Q
I 4
Q
Sample Output
1
2
3
# include <iostream> # include <cstdio> # include <cstring> # include <algorithm> # include <string> # include <cmath> # include <queue> # include <list> # define LL long long using namespace std ; struct ss { friend bool operator<(const ss a,const ss b) { if(a.v>b.v) return 1; else return 0; } int v; }; int main() { //freopen("in.txt","r",stdin) ; int n , k ; char s[10]; while(scanf("%d %d" , &n , &k) != EOF) { priority_queue<ss> q ; ss t; while(n--) { scanf("%s",s); if(s[0]=='I') { int a; scanf("%d",&a); t.v=a; q.push(t); if(q.size()>k) { q.pop(); } } else { printf("%d\n",q.top()); } } } return 0; }View Code
相关文章推荐
- UVA - 455 Periodic Strings
- 第十九篇:猜图游戏UI完整代码
- @suppressWarnings("unchecked") java 中是什么意思 (一般放dao查询方法上)
- SFTP+OpenSSH+ChrootDirectory
- poj2018 Best Cow Fences
- 白话经典算法系列之十三 随机生成和为S的N个正整数——投影法
- Telephone directory - SGU 127(水)
- HDU 4274 Spy's Work (树形DP,模拟)
- CentOS LAMP环境 配置详解
- 查看s3某目录占用的空间大小
- 10g Cluster启动OGG后Jagent无法跟随启动
- PAT(甲级)1032
- webview API详解
- 深入理解C++枚举类型enum
- Excel Sheet Column Title
- iOS开发 ----- AFNetWorkingSession
- URAL 1033 Labyrinth
- uva 12034 Race(递推+组合数)
- 作业
- zookeeper配置详解