您的位置:首页 > 产品设计 > UI/UE

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.

#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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: