HDU 4006 优先队列
The kth great number
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others)
Total Submission(s): 10390 Accepted Submission(s): 4153
Ming and Xiao Bao are playing a simple Numbers game. In a
round Xiao Ming can choose to write down a number, or ask
Xiao Bao what the kth great number is. Because the number
written by Xiao Ming is too much, Xiao Bao is feeling giddy. Now, try to
help Xiao Bao.
are several test cases. For each test case, the first line of input
contains two positive integer n, k. Then n lines follow. If Xiao Ming
choose to write down a number, there will be an " I" followed by a
number that Xiao Ming will write down. If Xiao Ming choose to ask Xiao
Bao, there will be a "Q", then you need to output the kth great number.
Xiao 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<queue>
#include<functional>
#include<vector>
using namespace std;
int n,k;
int main()
{
char ch[];
int x;
while(scanf("%d%d",&n,&k)!=EOF)
{
priority_queue<int,vector<int>,greater<int> >que;
while(n--)
{
scanf("%s",ch);
if(ch[]=='I')
{
scanf("%d",&x);
que.push(x);
}
else
{
printf("%d\n",que.top());
}
if(que.size()>k)
que.pop();
}
}
return ;
}
HDU 4006 优先队列的更多相关文章
- hdu 4006 优先队列 2011大连赛区网络赛F **
签到题都要想一会 #include<cstdio> #include<iostream> #include<algorithm> #include<cstri ...
- HDU 4006优先队列
//按照降序排列,而且队列中只保存k个元素 #include<stdio.h> #include<queue> using namespace std; int main(){ ...
- hdu 4006 The kth great number (优先队列)
/********************************************************** 题目: The kth great number(HDU 4006) 链接: h ...
- hdu 4006 The kth great number(优先队列)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4006 题目大意: 第一行 输入 n k,后有 n 行,对于每一行有两种状态 ,①“I x” : 插入 ...
- HDU 4006 The kth great number(multiset(或者)优先队列)
题目 询问第K大的数 //这是我最初的想法,用multiset,AC了——好吧,也许是数据弱也有可能 //multiset运用——不去重,边插入边排序 //iterator的运用,插入的时候,如果是相 ...
- HDU 4006 The kth great number【优先队列】
题意:输入n行,k,如果一行以I开头,那么插入x,如果以Q开头,则输出第k大的数 用优先队列来做,将队列的大小维护在k这么大,然后每次取队首元素就可以了 另外这个维护队列只有k个元素的时候需要注意一下 ...
- HDU 4006 The kth great number 优先队列、平衡树模板题(SBT)
The kth great number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Oth ...
- HDU 4006 The kth great number (优先队列)
The kth great number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Oth ...
- hdu 4006 第K大的数(优先队列)
N次操作 I是插入一个数 Q是输出第K大的数 Sample Input8 3 //n kI 1I 2I 3QI 5QI 4Q Sample Output123 # include <iostre ...
随机推荐
- JS对Array进行自定制排序
JS对Array进行自定制排序,简单的做一个记录,代码如下所示: //Test function function myFunction(){ var myArr = new Array(); var ...
- BZOJ 1503: [NOI2004]郁闷的出纳员 splay
1503: [NOI2004]郁闷的出纳员 Description OIER公司是一家大型专业化软件公司,有着数以万计的员工.作为一名出纳员,我的任务之一便是统计每位员工的工资.这本来是一份不错的工作 ...
- 【rqnoj39】 饮食问题
题目描述 Bessie 正在减肥,所以她规定每天不能吃超过 C (10 <= C <= 35,000)卡路里的食物.农民 John 在戏弄她,在她面前放了B (1 <= B < ...
- 关于css的全面学习笔记
1.text-align 属性规定元素中的文本的水平对齐方式.该属性通过指定行框与哪个点对齐,从而设置块级元素内文本的水平对齐方式.通过允许用户代理调整行内容中字母和字之间的间隔,可以支持值 just ...
- no-jquery 01Elements
Select Elements id // IE 5.5+ document.getElementById('myElement'); // IE 8+ document.querySelector( ...
- dubbo服务治理框架设计
dubbo.JSF作为使用最广泛的服务端框治理架,其设计和实现思想值得进行学习研究. 整个服务管理框架核心的原理基于反射以及socket调用实现,服务管理框架包含服务的注册管理 服务的索引管理以及服务 ...
- PHP 采集
<?php header("content-type:text/html;charset=gbk"); // 要采集的页面的地址 $url = "http://ww ...
- POJ1904 King's Quest(完备匹配可行边:强连通分量)
题目大概就是说给一张二分图以及它的一个完备匹配,现在问X部的各个点可以与Y部那些些点匹配,使得X部其余点都能找到完备匹配. 枚举然后匹配,当然不行,会超时. 这题的解法是,在二分图基础上建一个有向图: ...
- ggplot2包--R可视化
1.ggplot2发展历程 ggplot2是Hadley在爱荷华州立大学博士期间的作品,也是他博士论文的主题之一,实际上ggplot2还有个前身ggplot,但后来废弃了,某种程度上这也是Hadley ...
- CF# Educational Codeforces Round 3 E. Minimum spanning tree for each edge
E. Minimum spanning tree for each edge time limit per test 2 seconds memory limit per test 256 megab ...