hdu 4006 The kth great number

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4006

思路:利用优先队列的性质,将数据存入后会自动对数据进行排序

 1 #include<stdlib.h>
 2 #include<time.h>
 3 #include <cstdio>  
 4 #include <cstring>  
 5 #include <cmath>  
 6 #include <cstdlib>  
 7 #include <ctime>  
 8 #include <iostream>  
 9 #include <algorithm>  
10 #include <vector>  
11 #include <queue>  
12 #include <map>  
13 #include <set>  
14 #include <string>  
15 using namespace std;
16 
17 int main()
18 {
19     int n,k,a;
20     string str;
21     while(scanf("%d %d",&n,&k)!=EOF)
22     {
23         priority_queue<int,vector<int>,greater<int> > q;
24         while(n--)
25         {
26             cin>>str;
27              if(str.at(0) == 'I')
28              {
29                  scanf("%d",&a);
30                  q.push(a);
31                  if(q.size()>k)
32                  q.pop();
33              }
34              else
35                  cout<<q.top()<<endl;
36         }
37     }
38     return 0;
39 }
原文地址:https://www.cnblogs.com/pter/p/4936715.html