HDU 4006 The kth great number (priority queue • K-largest)

Source: Internet
Author: User

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)

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.