8 3 I 1 I 2 I 3 Q I 5 Q I 4 Q
1 2 3思路:优先队列+贪心HintXiao 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<iostream> #include<queue> using namespace std; int main() { int m,n,i,a; char c; priority_queue<int, vector<int>, greater<int> >que; while(cin>>m>>n) { while(!que.empty()) { que.pop(); } for(i=0;i<m;i++) { cin>>c; if(c==‘I‘) { cin>>a; que.push(a); if(que.size()>n) que.pop(); } else if(c==‘Q‘) { cout<<que.top()<<endl; } } } system("pause"); return 0; }
HDOJ 4006 The kth great number,布布扣,bubuko.com
HDOJ 4006 The kth great number
原文地址:http://blog.csdn.net/an327104/article/details/26229785