Hdoj 4006 The kth great number "Priority queue"

Source: Internet
Author: User

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"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.