hdu 1873看病要排隊(優先隊列)

來源:互聯網
上載者:User

標籤: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看病要排隊(優先隊列)

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.