HDU 4006优先队列

 1 //按照降序排列,而且队列中只保存k个元素
 2 
 3 #include<stdio.h>
 4 
 5 #include<queue>
 6 using namespace std;
 7 
 8 int main(){
 9     int n,k;
10     while(~scanf("%d%d",&n,&k)){
11         priority_queue<int,vector<int>,greater<int> > q;
12         for(int i=0;i<n;i++){
13             char c[10];
14             scanf("%s",c);
15             if(c[0]=='I'){
16                 int a;
17                 scanf("%d",&a);
18                 q.push(a);
19                 if(q.size()>k){
20                     q.pop();
21                 }
22             }
23             else{
24                 printf("%d
",q.top());
25             }
26         }
27     }
28 }
原文地址:https://www.cnblogs.com/Stomach-ache/p/3703203.html