The kth great number

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.

InputThere 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. 
OutputThe 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

Hint

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).

开一个multiset(允许存在相同值的集合且加入后自动排序),维护k个元素,多出在头部删除,最后取第一个元素即可,适用于找第几大第几小的题。
#include<stdio.h>
#include<set>
using namespace std;
int main()
{
int n,k,x,i;
char c;
while(~scanf("%d%d",&n,&k)){
multiset<int> a;
for(i=;i<=n;i++){
getchar();
scanf("%c",&c);
if(c=='I'){
scanf("%d",&x);
a.insert(x);
if(a.size()>k) a.erase(a.begin());
}
else printf("%d\n",*a.begin());
}
}
return ;
}

HDU - 4006 The kth great number multiset应用(找第k大值)的更多相关文章

  1. 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 ...

  2. HDU 4006 The kth great number(multiset(或者)优先队列)

    题目 询问第K大的数 //这是我最初的想法,用multiset,AC了——好吧,也许是数据弱也有可能 //multiset运用——不去重,边插入边排序 //iterator的运用,插入的时候,如果是相 ...

  3. hdu 4006 The kth great number (优先队列)

    /********************************************************** 题目: The kth great number(HDU 4006) 链接: h ...

  4. hdu 4006 The kth great number(优先队列)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4006 题目大意: 第一行 输入 n k,后有 n 行,对于每一行有两种状态 ,①“I x” : 插入 ...

  5. HDU 4006 The kth great number (优先队列)

    The kth great number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Oth ...

  6. hdu 4006 The kth great number

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4006 思路:利用优先队列的性质,将数据存入后会自动对数据进行排序 #include<stdlib ...

  7. HDU 4006 The kth great number【优先队列】

    题意:输入n行,k,如果一行以I开头,那么插入x,如果以Q开头,则输出第k大的数 用优先队列来做,将队列的大小维护在k这么大,然后每次取队首元素就可以了 另外这个维护队列只有k个元素的时候需要注意一下 ...

  8. HDU 4006 The kth great number AVL解

    提供动态更新数据.第实时QK大量的值什么? 使用AVL统计数据结构做,比较先进的数据结构的内容. 不知道给出的数据为准值是否有反复.下面的程序是因为我能够处理重复数据出现的情况下,. 了repeat的 ...

  9. HDU 2639(01背包求第K大值)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2639 Bone Collector II Time Limit: 5000/2000 MS (Jav ...

随机推荐

  1. Vue 资源

    一. 资源教程 综合类 vuejs 英文资料 Vue中文资料总汇 Vue.js 的一些资源索引 vue资料 入门类 vue 快速入门 Vue.js 中文系列视频教程 on Laravist 英文教程 ...

  2. Java的泛型约束和限制

    不能用基本类型实例化类型参数 不能用类型参数代替基本类型:例如,没有Pair<double>,只有Pair<Double>,其原因是类型擦除.擦除之后,Pair类含有Objec ...

  3. 高性能MySQL(四)

    Schema与数据类型优化 需要优化的数据类型 更小的通常更好 简单就好 尽量避免NULL 整数类型 存储整数,有TINYINT.SMALLINT.MEDIUMINT.INT.BIGINT,分别使用8 ...

  4. 《AndroidStudio有用指南》反馈问题和建议

    <AndroidStudio有用指南>反馈问题和建议 IntelliJ IDEA在持续更新, Android Studio也在持续更新, 本书也将会持续更新. Android Studio ...

  5. [听听音乐]X-Ray Dog

    X-Ray Dog是一个专门为好莱坞电影预告配乐的音乐工作室. https://music.163.com/#/artist?id=105618 有空的时候听听.

  6. Spring mvc接受集合类型参数的方法

    public String xxxxx(String xxxx, String xxxxx, @RequestParam("parameterList[]") List<St ...

  7. 20181125 test

    1.对一些不确定性的东西,还是需要一些勇气进行尝试 2.多阅读blog上的大咖的文章肯定会有提高的

  8. tomcat servlet JSP common gateway interface 公共网关接口

    Tomcat主要充当servlet/JSP容器,不过它却有大量的功能可以与传统的Web服务器相媲美,对公共网关接口(Common Gateway Interface)的支持就是其中之一. 传统的Web ...

  9. 1 Maven简介

    一.构建(build)     清理.编译.测试.打包.部署等一系列操作. 二.maven介绍:     maven是一个强大的构建工具,能够帮助我们自动化构建过程:从清理(clean).编译(com ...

  10. SpringBoot-(3)-RestController接口参数

    一,无参接口: //无参接口 @RequestMapping("/appSecret") public String secret() { return "EK125EK ...