现在的位置: 首页 > 综合 > 正文

hdu1873 看病要排队

2018年04月23日 ⁄ 综合 ⁄ 共 489字 ⁄ 字号 评论关闭

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

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;
}

抱歉!评论已关闭.