hdu 1873 看病要排队

来源:互联网 发布:淘宝卖家旺旺号怎么看 编辑:程序博客网 时间:2024/05/22 05:15

优先队列简单题

 

 

#include <iostream>#include <stdio.h>#include <iostream>#include <string.h>#include <queue>#include <vector>using namespace std;struct node{    int n;    int i;    friend bool operator < (node a, node b)    {        if(a.n==b.n)             return a.i>b.i;         else             return a.n<b.n;    }};int main(){    int n,A,B;    node t;    int k;    char s[4];    while(scanf("%d",&n)!=EOF)    {        k=1;        priority_queue<node> Q[4];        while(n--)        {           scanf("%s",s);           if(s[0]=='I')           {               scanf("%d%d",&A,&B);               t.n=B;               t.i=k++;               Q[A].push(t);           }           else           {               scanf("%d",&A);               if(!Q[A].empty())               {                   t=Q[A].top();                   Q[A].pop();                   printf("%d\n",t.i);               }               else               {                   printf("EMPTY\n");               }           }        }    }    return 0;}


 

原创粉丝点击