標籤:hdu 1873 namespace struct
# include <stdio.h># include <algorithm># include <queue>using namespace std;struct node{int y;int val;int num;friend bool operator<(node n1,node n2){if(n1.val==n2.val)return n1.num>n2.num;//從小到大return n1.val<n2.val;//從大到小}};struct node temp;int main(){int n,i,a,b;int t;char s[5];priority_queue<node> A,B,C;while(~scanf("%d",&n)){t=0;while(!A.empty())A.pop();while(!B.empty())B.pop();while(!C.empty())C.pop();for(i=0;i<n;i++){scanf("%s",s);if(strcmp(s,"IN")==0){scanf("%d%d",&a,&b);if(a==1){temp.val=b;temp.num=++t;A.push(temp);//A醫生}else if(a==2){temp.val=b;temp.num=++t;B.push(temp);//B醫生}else{temp.val=b;temp.num=++t;C.push(temp);//C醫生}}else{scanf("%d",&a);if(a==1){if(A.empty()){printf("EMPTY\n"); continue;}temp=A.top();A.pop();printf("%d\n",temp.num);}else if(a==2){if(B.empty()){printf("EMPTY\n"); continue;}temp=B.top();B.pop();printf("%d\n",temp.num);}else{if(C.empty()){printf("EMPTY\n"); continue;}temp=C.top();C.pop();printf("%d\n",temp.num);}}}}return 0;}
hdu 1873看病要排隊(優先隊列)