The kth great number

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

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
 

题意:遇见I输入数据遇见Q输出数据中第k大的数

如1 2 3 4 5    3为第k(3)大的数据

其中I Q使用字符输入时容易出错建议使用字符串输入

  

#include<stdio.h>
#include<string.h>
#include<queue>
using namespace std;
int main()
{
int n,m,j,i,t,k;
char a[5];
while(scanf("%d%d",&n,&m)!=EOF)
{
priority_queue<int,vector<int>,greater<int> >q;//按照从小到大的顺序定义的优先队列
while(n--)
{
getchar();
scanf("%s",a);
if(a[0]=='I')
{
scanf("%d",&k);
q.push(k);
}
else
{
while(q.size()>m)
q.pop();
t=q.top();
printf("%d\n",t);
}
}
}
return 0;
}

  

hdoj 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 (优先队列)

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

  5. C - The kth great number 优先队列

    Xiao Ming and Xiao Bao are playing a simple Numbers game. In a round Xiao Ming can choose to write d ...

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

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

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

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

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

  9. hdu 4006 The kth great number

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

随机推荐

  1. jquery api 笔记(2) 事件 事件对象

    事件 #1.resize()     缩放窗体:window.resizeTo(width, height); 并不是兼容做法.   #2 .scroll() ->获取滚动条的位置: .scro ...

  2. wcf通道Channel

    正文 客户端与服务进行交互的过程是通过通道进行交互的.客户端通过调用代理类执行相应的方法,通过通道编码,调用上下文,传输客户端的事务,管理可靠会话,对消息正文的加密,最后要执行的通道是传输通道就像我们 ...

  3. java String字符串——进度1

    String字符串    在JAVA中提供了多种创建字符串对象的方法,这里介绍最简单的两种,    第一种是直接赋值,    第二种是使用String类的构造方法:    如下所示:    Strin ...

  4. 将yyyyMMdd HH:mm:ss格式的时间转换成时间类型

    DateTime.ParseExact(gmt_withdrawal, "yyyyMMddHHmmss", System.Globalization.CultureInfo.Cur ...

  5. 【转载】C# Tutorial - Simple Threaded TCP Server

    http://tech.pro/tutorial/704/csharp-tutorial-simple-threaded-tcp-server In this tutorial I'm going t ...

  6. Java多线程初学者指南(8):从线程返回数据的两种方法

    从线程中返回数据和向线程传递数据类似.也可以通过类成员以及回调函数来返回数据.但类成员在返回数据和传递数据时有一些区别,下面让我们来看看它们区别在哪. 一.通过类变量和方法返回数据 使用这种方法返回数 ...

  7. bzoj 3065: 带插入区间K小值 替罪羊树 && AC300

    3065: 带插入区间K小值 Time Limit: 60 Sec  Memory Limit: 512 MBSubmit: 1062  Solved: 253[Submit][Status] Des ...

  8. 把内表 itab1 的 n1 到 n2 行内容附加到 itab2 内表中去.

    语法:append lines of itab1 [ from n1 ] [ to n2 ] to itab2. DATA:BEGIN OF gt_00 OCCURS 0,        l_01   ...

  9. 单片机系统与标准PC键盘的接口模块设计

    转自单片机系统与标准PC键盘的接口模块设计 概述     在单片机系统中,当输入按键较多时,在硬件设计和软件编程之间总存在着矛盾.对于不同的单片机系统需要进行专用的键盘硬件设计和编程调试,通用性差,使 ...

  10. 使用jxl.jar操作Excel

    在工程的build path中添加jxl.jar,网址:http://www.andykhan.com/jexcelapi/ import java.io.BufferedReader; import ...