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 ...
随机推荐
- 一定要学会paxos算法!
paxos算法 http://blog.csdn.net/dellme99/article/details/14162159
- loadrunner中变量和参数之间的转化实例
1.变量转换成参数值的两种方法: 方法一: char *test="Agoly"; lr_save_string(test,"testPa"); lr_e ...
- JavaScript给onclick事件赋值,动态传参数实例辩错
错误的例子: <body> <input id="certid" type="text" value="123456" & ...
- 领域模型(domain model)&贫血模型(anaemic domain model)&充血模型(rich domain model)
领域模型是领域内的概念类或现实世界中对象的可视化表示,又称为概念模型或分析对象模型,它专注于分析问题领域本身,发掘重要的业务领域概念,并建立业务领域概念之间的关系. 贫血模型是指使用的领域对象中只有s ...
- poj1061 Exgcd
#include<iostream> #include<cstdio> #include<algorithm> #include<cmath> usin ...
- HDU 5769 后缀数组
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5769 [2016多校contest-4] 题意:给定一个字符,还有一个字符串,问这个字符串存在多少个不 ...
- 01背包 ZOJ 3931 Exact Compression
题目连接 题意:n个数字构建哈夫曼树,问是否存在这样一棵树使得:(Fi数字大小,Ci哈夫曼表示下,'0'的数量) 分析:每次从优先队列取出两个数字可以互换位置,这样可以01互换.设a[i] <= ...
- Python基础10- 函数之内部函数与强制转换
#coding=utf-8 import mathimport osimport socket Python函数包括以下三类:内部函数.第三方函数和自定义函数内部函数包括:字符函数库.数学函数库.系统 ...
- jQuery入门第一天
使用jQuery之前,我们需要加一些代码到HTML文件中. 首先在页面顶端增加一行script元素,然后写上结束符. 浏览器会运行script 里所有的Javascript,包括jQuery. 在你的 ...
- 【Oracle】使用Oracle的v$sql视图查看近段时间执行的SQL语句
SELECT * FROM v$sql ORDER BY first_load_time DESC;