Hdoj 4006 The kth great number (priority queue)

Source: Internet
Author: User
Tags ming

The kth great number

Time limit:2000/1000 MS (java/others) Memory limit:65768/65768 K (java/others)
Total submission (s): 9415 Accepted Submission (s): 3756


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 HintXiao Ming won ' t ask Xiao Bao the kth great number when the number of the written number is smaller than K. (1=<k<=n& lt;=1000000).

Source the 36th ACM/ICPC Asia regional Dalian site--online Contest
#include <queue>#include<vector>#include<iostream>using namespacestd;intMain () {Charop[Ten]; intN, K, num;  while(Cin>>n >>k) {//Priority_queue<int, Vector<int>, cmp>q;priority_queue<int, vector<int, greater<int> >q;//small elements in the first team, the elements in order;         for(intI=0; i<n; i++) {cin>>op; if(op[0]=='I') {cin>>num; if(Q.size () <k) {Q.push (num); Continue; }                if(q.size () = =k) {if(num>Q.top ())                    {Q.pop (); Q.push (num); }                    }            }                Else{cout<<q.top () <<'\ n'; }        }    }    return 0;}

#include <vector>#include<queue>#include<iostream>using namespacestd;intMain () {priority_queue<int, vector<int> > Q;//default large elements in the team head;Q.push (Ten); Q.push (8); Q.push ( -); cout<<q.top () <<'\ n'; 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.