hdu4006(优先队列)
来源:互联网 发布:商品条形码数据库 编辑:程序博客网 时间:2024/05/16 12:55
http://acm.hdu.edu.cn/showproblem.php?pid=4006
分析:
有很多方法,不过如果想省事儿的话,
还是用优先队列,只存前k大的数就行了。
#include<string.h>
#include<queue>
using namespace std;
struct point
{
int num;
friend bool operator<(point a,point b)
{
return a.num>b.num;
}
};
int main()
{
int n,k,i,j;
char a[2];
point next ,cur;
while(scanf("%d%d",&n,&k)!=EOF)
{
priority_queue<point>q;
i=0;
for(j=0;j<n;j++)
{
scanf("%s",a);
if(a[0]=='Q')
{
cur=q.top();
printf("%d\n",cur.num);
}
else
{
scanf("%d",&next.num);
if(i<k)
{
q.push(next);
i++;
}
else
{
cur=q.top();
if(next.num>cur.num)//如果next大于最优的则更新。
{
q.pop();
q.push(next);//入队
}
}
}
}
}
return 0;
}
- hdu4006(优先队列)
- 优先队列(priority)--hdu4006
- hdu4006优先队列
- HDU4006-优先队列
- HDU4006(优先队列)
- hdu4006 The kth great number(优先队列)
- hdu4006 The kth great number(优先队列)
- hdu4006 The kth great number(优先队列)
- HDU4006-The kth great number(优先队列)
- [优先队列] HDU4006 The kth great number
- HDU4006 The kth great number 优先队列
- hdu4006 The kth great number 优先队列
- HDU4006 The kth great number(优先队列)
- hdu4006
- hdu4006
- HDU4006
- HDU4006
- hdu4006
- 匿名类
- 管理者的减负之道
- Direct2D 几何图形绘制基础
- Windows Message Queue((hdu1509))基础题
- Android自定义Button按钮显示样式
- hdu4006(优先队列)
- 有序链表和并的递归写法和非递归写法(c语言)
- 理解kobeject
- 那些年,写过的代码
- linux之creat函数解析
- Android访问https服务
- 局部刷新
- 程序员之一 态度
- POJ 1002 487-3279 排序检索。