The kth great number

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others)
Total Submission(s): 9780    Accepted Submission(s): 3898

Problem Description
Xiao 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.
 
Input
There 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. 
 
Output
The output consists of one integer representing the largest number of islands that all lie on one line. 
 
Sample Input
8 3
I 1
I 2
I 3
Q
I 5
Q
I 4
Q
 
Sample Output
1
2
3
#include <cstdio>
#include <string.h>
#include <queue>
#include <vector>
using namespace std;
const int MAXN=;
int n,k;
int vis[MAXN];
int main()
{
while(scanf("%d%d",&n,&k)!=EOF)
{
memset(vis,,sizeof(vis));
priority_queue<int,vector<int>,greater<int> > que;
for(int i=;i<n;i++)
{
scanf("%*c");
char op;
scanf("%c",&op);
if(op=='I')
{
int x;
scanf("%d",&x);
if(!vis[x])
{
que.push(x);
}
if(que.size()>k)
{
int y=que.top();
vis[y]=;
que.pop();
}
}
else
{
int res=que.top();
printf("%d\n",res);
}
}
}
return ;
}

HDU4006(小根堆)的更多相关文章

  1. scala写算法-用小根堆解决topK

    topK问题是指从大量数据中获取最大(或最小)的k个数,比如从全校学生中寻找成绩最高的500名学生等等. 本问题可采用小根堆解决.思路是先把源数据中的前k个数放入堆中,然后构建堆,使其保持堆序(可以简 ...

  2. 让priority_queue支持小根堆的几种方法

    点击这里了解什么是priority_queue 前言 priority_queue默认是大根堆,也就是大的元素会放在前面 例如 #include<iostream> #include< ...

  3. T-shirt buying CodeForces - 799B (小根堆+STL)

    题目链接 思路: 由于题目说了只有1,2,3,三种色号的衣服,然后开三个对应色号的小根堆, 我是根据pair<int,int> 创建了一个以价格小的优先的优先队列. pair中的另外一个i ...

  4. CJOJ 2482 【POI2000】促销活动(STL优先队列,大根堆,小根堆)

    CJOJ 2482 [POI2000]促销活动(STL优先队列,大根堆,小根堆) Description 促销活动遵守以下规则: 一个消费者 -- 想参加促销活动的消费者,在账单下记下他自己所付的费用 ...

  5. 随手练——HDU Safe Or Unsafe (小根堆解决哈夫曼问题)

    HDU 2527 :http://acm.hdu.edu.cn/showproblem.php?pid=2527 哈夫曼树,学完就忘得差不多了,题目的意思都没看懂,有时间复习下,看了别人的才知道是怎么 ...

  6. 05-树6. Path in a Heap (25) 小根堆

    05-树6. Path in a Heap (25) Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://www.patest.cn/contes ...

  7. 优先队列实现 大小根堆 解决top k 问题

      摘于:http://my.oschina.net/leejun2005/blog/135085 目录:[ - ] 1.认识 PriorityQueue 2.应用:求 Top K 大/小 的元素 3 ...

  8. bzoj 1577: [Usaco2009 Feb]庙会捷运Fair Shuttle——小根堆+大根堆+贪心

    Description 公交车一共经过N(1<=N<=20000)个站点,从站点1一直驶到站点N.K(1<=K<=50000)群奶牛希望搭乘这辆公交车.第i群牛一共有Mi(1& ...

  9. poj2513 Fence Repair(小根堆)

    Description Farmer John wants to repair a small length of the fence around the pasture. He measures ...

随机推荐

  1. debian内核代码执行流程(三)

    接续<debian内核代码执行流程(二)>未完成部分 下面这行输出信息是启动udevd进程产生的输出信息: [ ]: starting version 175是udevd的版本号. 根据& ...

  2. linux开发应用程序到运行的过程

    1.给linux配置交叉编译环境 2.在windows下使用source insight写程序,一共有m个h文件,n个c文件,k个main函数 3.将源代码放在linux里 4.在源代码文件夹里新建m ...

  3. recovery 差分升级包制作超时【转】

    本文转载自:https://blog.csdn.net/csdn66_2016/article/details/73800349 我们在对android系统升级的时候,可以减少升级包的大小,只升级差异 ...

  4. windows10添加电源计划修改的快捷方案

    转自:http://news.mydrivers.com/1/431/431346.htm 由于目前的Windows 10预览版在UI方面还未优化到位,所以某些设置选项要想找出来是很难的,这时候如果能 ...

  5. HMM简单理解(来自quora&其他网上资料)

    转载自quora: 连接:https://www.quora.com/What-is-a-simple-explanation-of-the-Hidden-Markov-Model-algorithm ...

  6. Centos6.5安装php5.6.7

    1. 下载 官网:http://php.net/downloads.php wget http://cn2.php.net/get/php-5.6.7.tar.gz/from/this/mirror ...

  7. cern-cloud-architecture

    规模: 总体: 有26个Cell 一个数据中心运行控制节点,另外一个仅仅运行nova cell 统一,灵活 nova-api运行在VM中,当然需要至少一个部署在物理机上来启动VM. 每个cell只有一 ...

  8. 设计高效sql一般经验谈

      1不用在sql语句使用系统默认的保留关键字 2尽量用exists 和 not exists 代替 in 和 not in 这条在sql2005之后,在索引一样,统计信息一样的情况下,exists ...

  9. java: InputStreamReader将字节的输入流变成字符的输入流,OutputStreamWriter将字符的输出流变成字节的输出流

    InputStreamReader:将字节的输入流变成字符的输入流, OutputStreamWriter:将字符的输出流变成字节的输出流 //将缓冲区的内容读取,可以一次读取 //可以接收键盘的输入 ...

  10. 2017-01-15 微信小程序胡诌一

    2017年1月9日,正值iphone发布10周年,在2007年的1月9日,乔布斯发布了震惊世界的iphone,10年后张小龙正式推出了他的小程序,究竟何意也没有具体深究.最初的时候小程序并不叫小程序, ...