HDU Problem 4006 The kth great number 【队列】

来源:互联网 发布:pdf格式软件下载 编辑:程序博客网 时间:2024/05/24 01:41

The kth great number

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


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 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=<k<=n<=1000000).
 

Source
The 36th ACM/ICPC Asia Regional Dalian Site —— Online Contest
 

Recommend
lcy   |   We have carefully selected several similar problems for you:  4003 4007 4008 4005 4001 
 
#include <cmath>#include <queue>#include <stack>#include <cstdio>#include <cstring>#include <algorithm>#define MAX_N 1005using namespace std;const int INF = 0xffff;struct node{    int x;    friend bool operator < (node a, node b) {        return a.x > b.x;    }}temp;int main() {    int n, t, a;    char s[7];    while (scanf("%d%d", &n, &t) != EOF) {        priority_queue<node> que;        while (n--) {            scanf("%s", s);            if (s[0] == 'I') {                scanf("%d", &a);                temp.x = a;                que.push(temp);                while (que.size() > t) que.pop();            }            else {                printf("%d\n", que.top().x);            }        }    }    return 0;}


0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 超市买过期东西但没有小票怎么办 网购退货商家已收货而不退款怎么办 手机号被别人注册了京东怎么办 中通快递把我发的货弄坏了了怎么办 在淘宝获取不了丰巢柜提货码怎么办 京东快递提货码数手机号错了怎么办 腾讯手游助手不能玩刺激战场怎么办 刚收的京东快递质量有问题怎么办 拼多多买家接受信息没有声音怎么办 苹果6s外放声音有杂音怎么办 华为手机不小心把视频删了怎么办 电脑做完系统不显示声卡了怎么办 苹果手机自带浏览器看视频卡怎么办 pr剪辑的时候视频太卡怎么办 小米手机忘记登录账号密码了怎么办 石膏线条软模硅胶模具气泡多怎么办 京东白条开通失败怎么办金牌用户 买家说我运费险没赔要投诉我怎么办 包邮有运费险的东西想退货怎么办 高锰酸钾沾到龟头上形成黑点怎么办 淘宝发货包邮买家退款运费怎么办 京东实名认证的手机号不用了怎么办 淘宝退货在自提柜 卖家不取怎么办 如果买家退货那卖家送的东西怎么办 陆金所注册手机号被占用要怎么办 重新登录而忘记密码和验证码怎么办 手机清理垃圾清掉的照片怎么办 收件人名字写错了拿不到快递怎么办 档案回原籍收件人写错了怎么办 寄申通快递收件人电话写错了怎么办 第三方支付倒闭了用户的钱怎么办啊 京东配送日期内货没送到家怎么办 拼多多拼单不成功优惠券退吗怎么办 退货退错了不发回来怎么办 商家总是不发退货地址过来怎么办 美团外卖下单后电话没改怎么办 从日本邮寄东西到中国被扣怎么办 淘宝拒收卖家收到货不退款怎么办 拒收的快递丢了卖家拒绝退款怎么办 京东买了东西超过七天想退货怎么办 微信买东西支付宝付款被骗怎么办