The kth great numberTime
limit:2000/1000 MS (java/others) Memory limit:65768/65768 K (java/others)
Total submission (s): 6982 Accepted Submission (s): 2837
Problem Descriptionxiao 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.
Inputthere 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.
Outputthe 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
123HintXiao 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).
Sourcethe 36th ACM/ICPC Asia Regional Dalian site--online Contest
Recommendlcy | We have carefully selected several similar problems for you:4003 4007 4004 4008 4005
Test instructions: N operations, ' I ' indicates the insertion value, Q asks you what the number of K is.
The priority queue Priority_queue<int, Vector<int>, greater<int> > use, each insertion of a number are saved before the number of K, the team head for the first number of K.
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <string > #include <algorithm> #include <cstdlib> #include <set> #include <queue> #include <stack > #include <vector> #include <map> #define N 100010#define Mod 10000007#define Lson l,mid,idx<<1# Define Rson mid+1,r,idx<<1|1#define LC idx<<1#define RC idx<<1|1typedef long long ll;const int INF = 100 0010;using namespace Std;int main () {int n, K; while (Cin >> n >> k) {char C; int s; Priority_queue<int, Vector<int>, greater<int> >que;///from large to small, team-to-minimum while (n--) { scanf ("%c%*c", &c); if (c = = ' Q ') printf ("%d\n", Que.top ()); else {scanf ("%d", &s); Que.push (s); if (Que.size () > K) que.pop (); GetChar); }}} return 0;}
HDU 4006 The kth great number (priority queue)