The kth great number
Time limit:2000/1000 MS (java/others) Memory limit:65768/65768 K (java/others)
Total submission (s): 8246 Accepted Submission (s): 3261
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 Input8 3I 1I 2I 3QI 5QI 4Q
Sample Output123
Test instructions: Meet I input data meet Q output data of k large number
such as 1 2 3 4 5 3 for the data of the K (3) Large
Where I q is error-prone, it is recommended to use string input when using character input
#include <stdio.h> #include <string.h> #include <queue>using namespace Std;int main () {int n,m,j,i,t,k ; Char A[5];while (scanf ("%d%d", &n,&m)!=eof) {priority_queue<int,vector<int>,greater<int> >q;//the priority queue as defined in order from small to large (n--) {GetChar (); scanf ("%s", a), if (a[0]== ' I ') {scanf ("%d", &k); Q.push (k);} Else{while (Q.size () >m) Q.pop (); T=q.top ();p rintf ("%d\n", t);}} return 0;}
Hdoj 4006 The kth great number "Priority queue"