The kth great number

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

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
题意:
共有n种操作,I插入一个数,Q询问第K大的数是几。
代码:
学会了优先队列
 #include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<functional>
#include<vector>
using namespace std;
int n,k;
int main()
{
char ch[];
int x;
while(scanf("%d%d",&n,&k)!=EOF)
{
priority_queue<int,vector<int>,greater<int> >que;
while(n--)
{
scanf("%s",ch);
if(ch[]=='I')
{
scanf("%d",&x);
que.push(x);
}
else
{
printf("%d\n",que.top());
}
if(que.size()>k)
que.pop();
}
}
return ;
}

HDU 4006 优先队列的更多相关文章

  1. hdu 4006 优先队列 2011大连赛区网络赛F **

    签到题都要想一会 #include<cstdio> #include<iostream> #include<algorithm> #include<cstri ...

  2. HDU 4006优先队列

    //按照降序排列,而且队列中只保存k个元素 #include<stdio.h> #include<queue> using namespace std; int main(){ ...

  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(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 优先队列、平衡树模板题(SBT)

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

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

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

  9. hdu 4006 第K大的数(优先队列)

    N次操作 I是插入一个数 Q是输出第K大的数 Sample Input8 3 //n kI 1I 2I 3QI 5QI 4Q Sample Output123 # include <iostre ...

随机推荐

  1. android MPAndroidChart饼图实现图例后加数字或文本(定制图例)

    转载请注明:http://blog.csdn.net/ly20116/article/details/50905789 MPAndroidChart是一个非常优秀的开源图表库,MPAndroidCha ...

  2. Android 编程下的自定义 xmlns

    什么是 xmlns xmlns是 XML Namespaces 的缩写,中文名称是 XML命名空间. xmlns 使用规则 xmlns:namespace-prefix="namespace ...

  3. CodeForces 710F 强制在线AC自动机

    题目链接:http://codeforces.com/contest/710/problem/F 题意:维护一个集合,集合要求满足三种操作. 1 str:向集合插入字符串str(保证不会插入之前已经插 ...

  4. Python小例子(判断质数)

    只能被自己或者1整除的数为质数 num = int(input('请输入一个数:')) if num > 1: # 查看因子 for i in range(2, num): if (num % ...

  5. SpringBoot的简单应用以及部署

    1. 项目目录结构

  6. iOS __strong __weak @Strongify @Weakify

    @Strongify,@Weakify主要是在block中使用. 因为block一般都在对象内部声明.. 如果在block内部使用了当前对象的属性,就会造成循环引用(block拥有当前对象的地址,而当 ...

  7. java-嵌套类

    浏览以下内容前,请点击并阅读 声明 java允许在一个类中定义另外一个类,这就叫类嵌套.类嵌套分为两种,静态的称为静态嵌套类,非静态的又称为内部类. 使用嵌套类的原因: 能够将仅在一个地方使用的类合理 ...

  8. ccc 播放动画

    cc.Class({ extends: cc.Component, properties: { anim:cc.Animation, }, // use this for initialization ...

  9. BZOJ4449 : [Neerc2015]Distance on Triangulation

    首先拓扑,每次取出度数为$2$的点,这样可以把所有三角形都找到. 那么建出对偶图,会发现是一棵树. 对这棵树进行点分治,每次取出重心,DFS求出所有在里面的点,然后从重心$3$个点分别做一次BFS. ...

  10. [转]OpenVPN 安装与配置

    一.服务器端安装及配置 服务器环境:干净的CentOS6.3 64位系统 内网IP:10.143.80.116 外网IP:203.195.xxx.xxx OpenVPN版本:OpenVPN 2.3.2 ...