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. 2018-2019-2 20165114《网络对抗技术》Exp6 信息收集与漏洞扫描

    Exp6 信息收集与漏洞扫描 目录 一.实验目标与内容 二.实验后问题回答 三.实验过程记录 3.1 各种搜索技巧的应用 3.2 DNS IP注册信息的查询 3.3 基本的扫描技术 [主机发现] [端 ...

  2. MongoDB快速入门(五)- Where子句

    RDBMS Where子句等效于MongoDB 查询文档在一些条件的基础上,可以使用下面的操作 操作 语法 示例 RDBMS等效语句 Equality {<key>:<value&g ...

  3. kafka笔记(一)

    1.kafka应用场景 基于流数据的发布订阅消息系统.实时流数据的高效异步通信.基于流数据的高可用分布式存储! 不同的系统之间实时流数据管道; 2.官方一句话概括 kafka是一个分布式流数据平台:可 ...

  4. sshfs的挂载与卸载

    在CentOS中 sshfs的使用依赖EPEL(只安装sshfs不会出错,但是却无法使用) 挂载 安装EPEL rpm -i https://dl.fedoraproject.org/pub/epel ...

  5. (转)Openstack Cascading和Nova Cell

    Openstack是看着AWS成长起来的,这点毋庸置疑:所以AWS大规模商用已成事实的情况下,Openstack也需要从架构和产品实现上进行优化,以满足大规模商用的要求.从已有的实现来看其中两种方式值 ...

  6. Mssql 跨域查询

    有数据库test1和数据库test2.其中test1中有表 table1.table2:test2 中有表 table1.三个表的字段都为为:id.xingming.shijian.shuliang. ...

  7. 牛客练习赛7E 珂朵莉的数列

    题意:求所有子区间的逆序数对数之和 题解:树状数组维护,对于每一对逆序数(l,r)属于l*(n-r+1)个区间,计算每一对对结果的贡献即可,可用树状数组维护,sum维护(n-r+1),按逆序数那样操作 ...

  8. 卸载 Oracle 的 JDK

    mac $ java -version java version "1.8.0_66" Java(TM) SE Runtime Environment (build 1.8.0_6 ...

  9. 遍历Newtonsoft.Json.Linq.JObject

    JObject 遍历: 引用命名空间:using Newtonsoft.Json.Linq; JObject _jObject = JObject.Parse("{'ID':'001','M ...

  10. 实用工具类--第三方开源--Lazy

    下载地址 :https://github.com/ddwhan0123/Lazy 工具 描述 AnimationUtils 动画工具类 AppUtils APP相关信息工具类 AssetDatabas ...