hdu 4006 The kth great number

hdu 4006 的传送门->

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大的数,

解题思路:就是用set 简单搞一下就好了。。。。。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
using namespace std;
//注意啦!!!!
multiset <int> s;//注意这里是multiset,是有重复的
multiset <int> ::iterator it;
char st[2];
int main()
{
    int m,k,x;
    while(~scanf("%d%d",&m,&k))
    {
        s.clear();
        while(m--)
        {
            scanf("%s",st);
            if(st[0] == 'I')
            {
                scanf("%d",&x);
                s.insert(x);
                if(s.size()>k)
                    s.erase(s.begin());
            }
            else
            {
                it=s.begin();
                printf("%d\n",*it);
            }
        }
    }
    return 0;
}
时间: 2024-08-03 05:52:44

hdu 4006 The kth great number的相关文章

[LeetCode] Ugly Number II

Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 is the sequence of the first 10 ugly numbers. Note that 1 is typically treated as an

LeetCode All in One 题目讲解汇总(持续更新中...)

终于将LeetCode的免费题刷完了,真是漫长的第一遍啊,估计很多题都忘的差不多了,这次开个题目汇总贴,并附上每道题目的解题连接,方便之后查阅吧~ 如果各位看官们,大神们发现了任何错误,或是代码无法通过OJ,或是有更好的解法,或是有任何疑问,意见和建议的话,请一定要在对应的帖子下面评论区留言告知博主啊,多谢多谢,祝大家刷得愉快,刷得精彩,刷出美好未来- 博主制作了一款iOS的应用"Leetcode Meet Me",里面有Leetcode上所有的题目,并且贴上了博主的解法,随时随地都能

HDU 1266 Reverse Number (water ver.)

http://acm.hdu.edu.cn/showproblem.php?pid=1266 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Problem Description Welcome to 2006'4 computer college programming contest! Specially, I give my best regards to all fresh

hdu 1394 Minimum Inversion Number

hdu 1394 的传送门 Problem Description The inversion number of a given number sequence a1, a2, -, an is the number of pairs (ai, aj) that satisfy i < j and ai > aj. For a given sequence of numbers a1, a2, -, an, if we move the first m >= 0 numbers to

HDU 2281 Square Number: Pell方程及数论

http://acm.hdu.edu.cn/showproblem.php?pid=2281 思路: 原式化为:m^2-48x^2=1,(m=4n+3) 立即得到最小正整数解:m1=7,x1=1 后面就和uva 138一样了. 注意:得到mk后还要判断(mk-3)%4==0才能加到n中,详见代码. 完整代码: 01./*31ms,276KB*/ 02. 03.#include<cstdio> 04.#include<vector> 05.using namespace std; 0

hdu 3509 Buge&amp;#39;s Fibonacci Number Problem

点击此处即可传送 hdu 3509 题目大意:F1 = f1, F2 = f2;; F(n) = a*F(n-1) + b*F(n-2); S(n) = F1^k + F2^k +-.+Fn^k; 求S(n) mod m; 解题思路: 1:首先一个难题就是怎么判断矩阵的维数(矩阵的维数是个变量) 解决方法:开一个比较大的数组,然后再用一个公有变量记一下就行了,具体详见代码: 2:k次方,找规律: 具体上代码吧: /* 2015 - 8 - 16 晚上 Author: ITAK 今日的我要超越昨日

hdu 4279 Number

点击打开链接hdu 4279 1思路:数学题+找规律2分析:           1这一题的数据范围很大(1---z^63-1),而给定的时间才1s.那么明显就是找规律的题目,但是要怎么找到这个规律呢,我们一般先用打表输出前100或前50左右的数据找到规律就可以根据规律来写.           2由于是要求[x,y]这个闭区间的内满足的个数,那么我们想到了就是相减.把[1,y]-[1,x-1]这里为什么不是[1,x]呢,由于这里是闭区间那么这里的x是要考虑的所以不能直接减去.         

HDOJ(HDU) 1562 Guess the number(水题,枚举就行)

Problem Description Happy new year to everybody! Now, I want you to guess a minimum number x betwwn 1000 and 9999 to let (1) x % a = 0; (2) (x+1) % b = 0; (3) (x+2) % c = 0; and a, b, c are integers between 1 and 100. Given a,b,c, tell me what is the

hdu 1711 Number Sequence

点击打开链接hdu1711 思路:KMP kmp算法: 1 kmp是用来匹配字符串,只能够匹配单一的字符串 2 kmp的算法的过程:   1:假设文本串的长度为n,模式串的长度为m:   2:先例用O(m)的时间去预处理next数组,next数组的意思指的是当前的字符串匹配失败后要转到的下一个状态:   3:利用o(n)的时间去完成匹配: 3 时间复杂度为o(n+m)即o(n): 代码: #include<algorithm> #include<iostream> #include