0
点赞
收藏
分享

微信扫一扫

HDU1873 看病要排队

yundejia 2023-04-20 阅读 38


E - 看病要排队


Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u



Description



看病要排队这个是地球人都知道的常识。
不过经过细心的0068的观察,他发现了医院里排队还是有讲究的。0068所去的医院有三个医生(汗,这么少)同时看病。而看病的人病情有轻重,所以不能根据简单的先来先服务的原则。所以医院对每种病情规定了10种不同的优先级。级别为10的优先权最高,级别为1的优先权最低。医生在看病时,则会在他的队伍里面选择一个优先权最高的人进行诊治。如果遇到两个优先权一样的病人的话,则选择最早来排队的病人。

现在就请你帮助医院模拟这个看病过程。



 



Input



输入数据包含多组测试,请处理到文件结束。
每组数据第一行有一个正整数N(0<N<2000)表示发生事件的数目。
接下来有N行分别表示发生的事件。
一共有两种事件:
1:"IN A B",表示有一个拥有优先级B的病人要求医生A诊治。(0<A<=3,0<B<=10)
2:"OUT A",表示医生A进行了一次诊治,诊治完毕后,病人出院。(0<A<=3)



 



Output



对于每个"OUT A"事件,请在一行里面输出被诊治人的编号ID。如果该事件时无病人需要诊治,则输出"EMPTY"。
诊治人的编号ID的定义为:在一组测试中,"IN A B"事件发生第K次时,进来的病人ID即为K。从1开始编号。



 



Sample Input



7 IN 1 1 IN 1 2 OUT 1 OUT 2 IN 2 1 OUT 2 OUT 1 2 IN 1 1 OUT 1



 



Sample Output



2 EMPTY 3 1 1



 







中文题题意读懂了...就是个优先队列....









#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<string>
#include<stdlib.h>
#include<functional>
#include<queue>
#include<vector>

using namespace std;

struct node
{
    int x, y;
    friend bool operator< (node a, node b)
    {
        if(a.x!=b.x)
        {
            return a.x < b.x;
        }
        else
        {
            return a.y > b.y;
        }
    }
};


int main()
{

    int n;
    while(scanf("%d",&n)!=EOF)
    {
        int h = 1;
        priority_queue<node>q1;
        priority_queue<node>q2;
        priority_queue<node>q3;
        /*priority_queue<int>q1;
        priority_queue<int>q2;
        priority_queue<int>q3;*/
        string aa;
        int a,b;
        for(int i=0;i<n;i++)
        {
            cin >> aa;
            if(aa == "IN")
            {
                struct node p;
                scanf("%d%d",&a,&b);
                p.x = b;
                p.y = h;
                if(a == 1)
                {
                    q1.push(p);
                }
                else if(a == 2)
                {
                    q2.push(p);
                }
                else if(a == 3)
                {
                    q3.push(p);
                }
                h++;
            }
            else
            {
                scanf("%d",&a);
                if(a == 1)
                {
                    if(!q1.empty())
                    {
                        struct node tt;
                        tt = q1.top();
                        q1.pop();
                        printf("%d\n",tt.y);
                    }
                    else
                    {
                        printf("EMPTY\n");
                    }
                }
                else if(a == 2)
                {
                    if(!q2.empty())
                    {
                        struct node tt;
                        tt = q2.top();
                        q2.pop();
                        printf("%d\n",tt.y);
                    }
                    else
                    {
                        printf("EMPTY\n");
                    }
                }
                else if(a == 3)
                {
                    if(!q3.empty())
                    {
                        struct node tt;
                        tt = q3.top();
                        q3.pop();
                        printf("%d\n",tt.y);
                    }
                    else
                    {
                        printf("EMPTY\n");
                    }
                }
            }
        }
    }
    return 0;
}






举报

相关推荐

0 条评论