Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4278 Accepted Submission(s): 1770
7 IN 1 1 IN 1 2 OUT 1 OUT 2 IN 2 1 OUT 2 OUT 1 2 IN 1 1 OUT 1
2 EMPTY 3 1 1
#include<iostream> #include<cstdio> #include<queue> #include<string> using namespace std; struct node { int id,p; friend bool operator<(node a,node b) { if(a.p!=b.p) return a.p<b.p; //优先度大的先出队 return a.id>b.id; //编号小的先出队 } }; int main() { int a,b,i,n; string s; node person; while(scanf("%d",&n)!=-1) { i=1; priority_queue<node>q[4]; while(n--) { cin>>s; if(s=="IN") { cin>>a>>b; person.p=b; person.id=i++; q[a].push(person); } else { cin>>a; if(q[a].empty()) cout<<"EMPTY"<<endl; else { person=q[a].top(); q[a].pop(); cout<<person.id<<endl; } } } } return 0; }
原文:http://blog.csdn.net/u011721440/article/details/20624433