STL优先队列的具体描写叙述
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1873
#include<stdio.h> #include<queue> using namespace std; struct node { int q,k; friend bool operator<(node a,node b)//先比較q的大小,假设相等就按k的大小排列 { if(a.q<b.q) return true; if(a.q==b.q&&a.k>b.k) return true; return false; } }; priority_queue<node>que[4];//队列数组 int main() { int n; while(~scanf("%d",&n)) { while(!que[1].empty())//清空 que[1].pop(); while(!que[2].empty()) que[2].pop(); while(!que[3].empty()) que[3].pop(); int h=0,a,c,i=1,m[2000]; char s[4]; node b; for(int j=0;j<n;j++) { scanf("%s",s); if(s[0]=='I')//进入 { scanf("%d %d",&a,&c); b.q=c; b.k=i++; que[a].push(b); } else//推断输出 { node b; scanf("%d",&a); if(que[a].empty()) printf("EMPTY "); else{printf("%d ",que[a].top().k); que[a].pop();} } } } return 0; }