HDU 4006 the kth great number

Source: Internet
Author: User
Tags ming

HDU 4006 Portal

Problem Description

Xiao 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.

Input

There 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.

Output

The output consists of one integer representing the largest number of islands that all lie on one line.

Sample Input

8 3
I 1
I 2
I 3
Q
I 5
Q
I 4
Q

Sample Output

1
2
3

The main idea: is I to add a number, Q for the output of the number of K,

Problem-solving ideas: Just use set simple to do a bit better .....

#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <set>using namespace STD;//NOTE!!!  multiset <int>S//Note here is Muiltiset, there are duplicates multiset <int>:: Iterator it;Charst[2];intMain () {intM,k,x; while(~scanf("%d%d", &m,&k)) {s.clear (); while(m--) {scanf('%s ', ST);if(st[0] ==' I ')            {scanf("%d", &x); S.insert (x);if(S.size () >k) s.erase (S.begin ()); }Else{It=s.begin ();printf("%d\n", *it); }        }    }return 0;}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

HDU 4006 the kth great number

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.