hdu1873 看病要排队

来源:互联网 发布:工作流程优化建议 编辑:程序博客网 时间:2024/04/30 02:48

主要是学习一下优先队列的使用

code:

#include <queue>#include <cstdio>using namespace std;struct node{    int id,lv;    friend bool operator < (const node x,const node y)    {        if(x.lv==y.lv)        {            return x.id>y.id;        }        return x.lv<y.lv;    }}tmp;int main(){    char str[5];    int n,i,a,b;    while(~scanf("%d",&n))    {        tmp.id=0;        priority_queue<node> q[4];        for(i=1;i<=n;i++)        {            scanf("%s",str);            if(str[0]=='I')            {                tmp.id++;                scanf("%d%d",&a,&b);                tmp.lv=b;                q[a].push(tmp);            }else{                scanf("%d",&a);                if(!q[a].empty())                {                    printf("%d\n",q[a].top().id);                    q[a].pop();                }else{                    puts("EMPTY");                }            }        }    }    return 0;}


原创粉丝点击