hdu 4006 The kth great number

这题虽然是线段树的作业,但我是用pq偷懒过的,它的思路和poj 1442差不多,但要简单。

 1 #include <stdio.h>
 2 #include <queue>
 3 using namespace std;
 4 int main()
 5 {
 6     int m,n,k,t,cnt;
 7     char ch;
 8     while(~scanf("%d%d",&m,&n))
 9     {
10         cnt = 0;
11         priority_queue <int> small;
12         priority_queue <int, vector<int>, greater<int> > big;
13         while(m--)
14         {
15             getchar();
16             scanf("%c",&ch);
17             if(ch == 'I')
18             {
19                 scanf("%d",&k);
20                 if(cnt < n-1)
21                 {
22                     big.push(k);
23                     cnt++;
24                 }
25                 else if(k > big.top())
26                 {
27                     t = big.top();
28                     big.pop();
29                     big.push(k);
30                     small.push(t);
31                 }
32                 else small.push(k);
33             }
34             else printf("%d\n",small.top());
35         }
36     }
37     return 0;
38 }
原文地址:https://www.cnblogs.com/lzxskjo/p/2591003.html