Test instructions dynamic Query K-Large number
Maintain the K number in the first priority queue with decimals if this number is less than the first element of the team, then you do not have to insert the first element of the team. This number is queued for each query, only the first element of the output team.
#include <cstdio> #include <queue>using namespace Std;int main () { int n, a, K; Char op[5]; while (~SCANF ("%d%d", &n, &k)) { priority_queue<int,vector<int>,greater<int> > PQ ; while (n--) { scanf ("%s", op); if (op[0] = = ' I ') { scanf ("%d", &a); if (Pq.size () <k) Pq.push (a); else if (a > Pq.top ()) Pq.push (a), Pq.pop (); } else printf ("%d\n", Pq.top ()); } } return 0;}
The kth great number
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).
HDU 4006 The kth great number (priority queue • K-largest)