Hdu 4006 The kth great number (第k大元素 优先队列的几种写法)
2014-02-13 19:57
357 查看
题意:不断地读入数据,询问第k大的是多少。
思路:维护只有k个元素且队首元素最小的优先队列
总结下常用的三种写法,个人还是喜欢结构体这种。
思路:维护只有k个元素且队首元素最小的优先队列
总结下常用的三种写法,个人还是喜欢结构体这种。
#include<cstdio> #include<queue> using namespace std; struct Node { int data; bool operator < (const Node b) const { return data>b.data; } }node; //重载 “()” 操作符 struct myComp { bool operator () (const int a,const int b) { return a>b; } }; int main () { int n,k,num; char str[4]; while (~scanf("%d%d",&n,&k)) { priority_queue<Node> Q; //priority_queue<int,vector<int>,greater<int> > Q; //priority_queue<int,vector<int>,myComp > Q; for (int i=1;i<=n;i++) { scanf("%s",str); if (str[0]=='I') { //scanf("%d",&num); scanf("%d",&node.data); Q.push(node); if (Q.size()>k) Q.pop(); } else printf("%d\n",Q.top()); } } return 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 (求动态第k大值【Treap】)
- 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 【优先队列求第K大数】
- hdu 4006 The kth great number(使用优先队列)
- HDU 4006 The kth great number(优先队列)