博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU - 4006 The kth great number multiset应用(找第k大值)
阅读量:4455 次
发布时间:2019-06-07

本文共 1566 字,大约阅读时间需要 5 分钟。

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 3I 1I 2I 3QI 5QI 4Q

Sample Output

123

Hint

Xiao  Ming  won't  ask  Xiao  Bao  the  kth  great  number  when  the  number  of  the  written number is smaller than k. (1=
<=n<=1000000). 开一个multiset(允许存在相同值的集合且加入后自动排序),维护k个元素,多出在头部删除,最后取第一个元素即可,适用于找第几大第几小的题。
#include
#include
using namespace std;int main(){ int n,k,x,i; char c; while(~scanf("%d%d",&n,&k)){ multiset
a; for(i=1;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 0;}

 

转载于:https://www.cnblogs.com/yzm10/p/7224375.html

你可能感兴趣的文章
图层时间之层级关系时间
查看>>
常见算法之0---冒泡排序
查看>>
Spring boot 默认首页配置
查看>>
host的作用
查看>>
为什么operator<<运算符重载一定要为友元函数
查看>>
jsonp跨域
查看>>
再温习JAVA命名规范
查看>>
libevent学习过程
查看>>
webview加载页面为什么在UI线程里面做,难道不是耗时操作么
查看>>
TensorFlow 安装 Ubuntu14.04
查看>>
springmvc 注解 RequestParam/RequestHeader/CookieValue
查看>>
20175310 《Java程序设计》第1周学习总结(1)安装虚拟机
查看>>
2016012016+小学四则运算练习软件项目报告
查看>>
Java入门系列(一)基础概览
查看>>
团队编程项目作业2-团队编程项目代码设计规范
查看>>
c# aspose 模版 简单导出execl
查看>>
codeforces 27E . Number With The Given Amount Of Divisors 搜索+数论
查看>>
奥斯卡设立流行奖,网友表示烂透了
查看>>
HDU 4114 Disney's FastPass
查看>>
Codeforces 509C Sums of Digits
查看>>