标签:hdu 4006 the kth great number 第k大数 优先队列
8 3 I 1 I 2 I 3 Q I 5 Q I 4 Q
1 2 3HintXiao 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<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<set>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#define N 100010
#define Mod 10000007
#define lson l,mid,idx<<1
#define rson mid+1,r,idx<<1|1
#define lc idx<<1
#define rc idx<<1|1
typedef long long ll;
const int INF = 1000010;
using namespace std;
int main()
{
int n, k;
while ( cin >> n >> k )
{
char c;
int s;
priority_queue<int, vector<int>, greater<int> >que;///从大到小排序,队首尾最小值
while ( n-- )
{
scanf ( "%c%*c", &c );
if ( c == 'Q' )
printf ( "%d\n", que.top() );
else
{
scanf ( "%d", &s );
que.push ( s );
if ( que.size() > k )
que.pop();
getchar();
}
}
}
return 0;
}
hdu 4006 The kth great number(优先队列)
标签:hdu 4006 the kth great number 第k大数 优先队列
原文地址:http://blog.csdn.net/acm_baihuzi/article/details/41554293