HDU 4006 K-Large number (priority queue)

Source: Internet
Author: User

n operations I is to insert a number q is the number of the output K large

Sample Input
8 3//n K
I 1
I 2
I 3
Q
I 5
Q
I 4
Q

Sample Output
1
2
3

1# include <iostream>2# include <cstdio>3# include <cstring>4# include <algorithm>5# include <string>6# include <cmath>7# include <queue>8# include <list>9# define LLLong LongTen using namespacestd; One  A structSS - { -FriendBOOL operator< (ConstSS A,ConstSS B) the     { -         if(a.v>B.V) -             return 1; -         Else +             return 0; -     } +     intv; A }; at  - intMain () - { -     //freopen ("In.txt", "R", stdin); -     intN, K; -     Chars[Ten]; in      while(SCANF ("%d%d", &n, &k)! =EOF) -     { toPriority_queue<ss>Q; + SS T; -          while(n--) the         { *scanf"%s", s); $             if(s[0]=='I')Panax Notoginseng             { -                 intA; thescanf"%d",&a); +t.v=A; A Q.push (t); the                 if(Q.size () >k) +                 { - Q.pop (); $                 } $             } -             Else -             { theprintf"%d\n", Q.top ()); -             }Wuyi         } the     } -  Wu     return 0; -}
View Code

Hdu 4006 K-Large 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.