HDU 4006 The kth great number【优先队列】
来源:互联网 发布:java必读书籍推荐 编辑:程序博客网 时间:2024/05/09 21:24
优先队列和普通队列区别在于 普通队列总是队尾入元素,队首出元素,而优先队列赋予元素优先级,优先级最高的先出队列。
题目:http://acm.hdu.edu.cn/showproblem.php?pid=4006
题意:输入n和k,接下来n个操作,I代表入队,Q代表输出队列中第k大数
所以可以维护一个有前k大的数的队列,每次输出最小数(最小即第k大)即可,需要自己写比较操作规则
#include<queue>#include<cstdio>using namespace std; struct cmp{bool operator ()(int &a,int &b){return a>b;}};int main(){int n,k,num;char ch,xishou;freopen("in.txt","r",stdin);priority_queue<int,vector<int>,cmp>q;while(~scanf("%d%d",&n,&k)){while(n--){scanf("%c%c",&xishou,&ch);if(ch == 'I'){scanf("%d",&num);q.push(num);if(q.size()>k){q.pop();//超过k的不需要,直接去掉队首(最小的)}}elseprintf("%d\n",q.top());//队首是最小的数}while(!q.empty()){q.pop();}}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(优先队列,好)
- ios 取消延迟调用的方法
- 从orale数据库中的表迁到sqlserver数据库表中
- day121(07.12)
- Flare-On Challenge2 Writeup
- 有关小米4发布会的感想
- HDU 4006 The kth great number【优先队列】
- oracle select 练习
- 前台与后台_调试过程
- iOS固定大小截图<支持图片的缩放>
- Hibernate关联关系映射(一对多/多对一)
- Android开源项目分类汇总
- 什么是JAVA开发环境、测试环境及生产环境,及它的过程
- 毕业季:小米的成人礼
- wiki 1913 数字梯形问题