The kth great number/hdoj 4006 2011 Regional Dalian Online priority queue
2011-09-04 14:39
459 查看
We can use priority queue to support the question.Firstly ,we push k number into priority queue. Then ,if the number bigger than the top number of the priority queue,push the number into the priority queue,or throw
out. If input 'Q',output the top
number of prority queue.
out. If input 'Q',output the top
number of prority queue.
#include <iostream> #include <cstdio> #include <cstring> #include <queue> using namespace std; int flag[1000010]; int main() { int n; char str[10]; int num; int i; int k; while(scanf("%d %d",&n,&k)!=EOF) { //priority_queue<int,vector<int>,less<int> > qu; priority_queue<int,vector<int>,greater<int> > qu; for(i=1;i<=n;i++) { scanf("%s",str); if(str[0]=='I') { scanf("%d",&num); if(i>k) { if(num>qu.top()) { qu.pop(); qu.push(num); } } else { qu.push(num); } } else if(str[0]=='Q') { printf("%d\n",qu.top()); } } } return 0; }
相关文章推荐
- HDOJ 4006 The kth great number
- [HDOJ4006]The kth great number
- [HDOJ] problem_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/(大连网赛1006)- The kth great number 剖析
- HDOJ 4006 The kth great number(优先队列)
- HDOJ-4006/(大连网赛1006)- 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 4006 The kth great number(优先队列)
- HDOJ 题目4006 The kth great number(优先队列水)
- HDOJ 4006 The kth great number(优先队列)
- hdoj-4006-The kth great number