HDU 1873 看病要排队

优先队列,水题。

三个医生,对应三个优先队列就可以了。

多组数据要初始化优先队列

#include<cstdio>
#include<cstring>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<stack>
#include<iostream>
#include<list>
#include<set>
#include<vector>
#include<cmath>

#define INF 0x7fffffff
#define eps 1e-8
#define LL long long
#define PI 3.141592654
#define CLR(a,b) memset(a,b,sizeof(a))
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FOR0(i,a,b) for(int i=a;i>=b;i--)
#define pb push_back
#define debug puts("==fuck==")
#define acfun std::ios::sync_with_stdio(false)

#define SIZE 20+10
using namespace std;
struct lx
{
    int value;
    int ID;
    friend bool operator <( lx a,lx b)
    {
        if(a.value==b.value)
            return a.ID>b.ID;
        return a.value<b.value;
    }
};
int main()
{
    int t;
    priority_queue<lx> q[4];
    int Id=1;
    while(scanf("%d",&t)!=EOF)
    {
        char head[11];
        scanf("%s",head);
        if(strcmp(head,"OUT")==0)
        {
            int value;
            scanf("%d",&value);
            if(q[value].empty())
                puts("EMPTY");
            else
            {
                lx now;
                now=q[value].top();
                q[value].pop();
                printf("%d\n",now.ID);
            }
        }
        else if(strcmp(head,"IN")==0)
        {
            int value;
            lx now;
            scanf("%d%d",&value,&now.value);
            now.ID=Id++;
            q[value].push(now);
        }
        t--;
        if(t==0)
        {
            FOR(i,1,4)
            {
                while(!q[i].empty())
                    q[i].pop();
            }
            Id=1;
        }
    }
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值