您的位置:首页 > 其它

hdu 4006 第K大的数(优先队列)

2015-09-24 20:05 260 查看

N次操作 I是插入一个数 Q是输出第K大的数

Sample Input
8 3 //n k
I 1
I 2
I 3
Q
I 5
Q
I 4
Q

Sample Output
1
2
3

 

# include <iostream>
# include <cstdio>
# include <cstring>
# include <algorithm>
# include <string>
# include <cmath>
# include <queue>
# include <list>
# define LL long long
using namespace std ;

struct ss
{
friend bool operator<(const ss a,const ss b)
{
if(a.v>b.v)
return 1;
else
return 0;
}
int v;
};

int main()
{
//freopen("in.txt","r",stdin) ;
int n , k ;
char s[10];
while(scanf("%d %d" , &n , &k) != EOF)
{
priority_queue<ss> q ;
ss t;
while(n--)
{
scanf("%s",s);
if(s[0]=='I')
{
int a;
scanf("%d",&a);
t.v=a;
q.push(t);
if(q.size()>k)
{
q.pop();
}
}
else
{
printf("%d\n",q.top());
}
}
}

return 0;
}
View Code

 

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: