HDU 4006 Portal
Problem Description
Xiao Ming and Xiao Bao is playing a simple Numbers game. In a round Xiao Ming can choose to write down a number, or ask Xiao Bao What's the kth great number is. Because the number written by Xiao Ming are too much, Xiao Bao is feeling giddy. Now, try-to-help Xiao Bao.
Input
There is several test cases. For each test case, the first line of input contains the positive integer n, K. then n lines follow. If Xiao Ming Choose to write down a number, there'll be is a "I" followed by a number that Xiao Ming would write down. If Xiao Ming Choose to ask Xiao Bao, there would be a "Q" and then your 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
The main idea: is I to add a number, Q for the output of the number of K,
Problem-solving ideas: Just use set simple to do a bit better .....
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <set>using namespace STD;//NOTE!!! multiset <int>S//Note here is Muiltiset, there are duplicates multiset <int>:: Iterator it;Charst[2];intMain () {intM,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;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
HDU 4006 the kth great number