The kth great number

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

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

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

 
Source
 
Recommend
lcy
 
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
#include<vector> using namespace std; int n,k;
priority_queue<int,vector<int>,greater<int> >q; int main(){ //freopen("input.txt","r",stdin); char op[];
int x;
while(~scanf("%d%d",&n,&k)){
while(!q.empty())
q.pop();
for(int i=;i<k;i++){
scanf("%s%d",op,&x);
q.push(x);
}
for(int i=k;i<n;i++){
scanf("%s",op);
if(op[]=='Q')
printf("%d\n",q.top());
else{
scanf("%d",&x);
if(x>q.top()){
q.pop();
q.push(x);
}
}
}
}
return ;
}

HDU 4006 The kth great number (优先队列)的更多相关文章

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

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

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

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

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

  4. HDU - 4006 The kth great number multiset应用(找第k大值)

    The kth great number Xiao Ming and Xiao Bao are playing a simple Numbers game. In a round Xiao Ming ...

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

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

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

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

  7. hdu 4006 The kth great number

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

  8. HDU 4006 The kth great number AVL解

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

  9. hdoj 4006 The kth great number【优先队列】

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

随机推荐

  1. linux命令学习——file

    1.简介 file命令是用来检测并显示文件类型(determine file type).通过file指令,我们得以辨识该文件的类型,例如可以知道动态连接库是32位还是64位. 2.命令格式 file ...

  2. w3cscholl的在线代码编辑工具2

    https://www.w3cschool.cn/tryrun/runcode?lang=c

  3. unity3d shader 学习

    [浅墨Unity3D Shader编程] 着色器参考 [Unity Shaders]

  4. 扩展一个boot的插件—tooltip&做一个基于boot的表达验证

    在线演示 本地下载 (代码太多请查看原文) 加班,加班加班,我爱加班··· 我已经疯了,哦也. 这次发一个刚接触boot的时候用boot做的表单验证,我们扩展一下tooltip的插件,让他可以换颜色. ...

  5. javax.validation.UnexpectedTypeException: No validator could be found for constraint 'org.hibernate.validator.constraints.Length' validating type

    使用hibernate validator出现上面的错误, 需要注意: @NotNull 和 @NotEmpty  和@NotBlank 区别 @NotEmpty 用在集合类上面@NotBlank 用 ...

  6. Swift语言精要 - 扩展(Extension)

    swift的Extension用户在不访问代码的情况下扩展基本结构类型或自定义类 extension Int { var doubled : Int { } func multiplyWith(ano ...

  7. LintCode: Combination Sum II

    C++ DFS class Solution { public: void help(vector<int> &a, int now, int sum, int target, v ...

  8. php 字符串中的\n换行符无效、不能换行的解决方法

    php 字符串中的\n换行符无效.不能换行的解决方法 程序的中的换行符\n会直接输出,无法正确换行,解决方法是把单引号改为双引号 aa

  9. Nginx反向代理转发Host设置

    默认情况下反向代理是不会转发请求中的Host头部,如果需要转发,则需要配置红色字体表示的选项参数. location /t02 { proxy_set_header Host $host; proxy ...

  10. SQL Server临时表

    []SQL Server临时表]()https://docs.microsoft.com/zh-cn/sql/relational-databases/tables/temporal-tables)