hdu1873-看病要排队-(结构体优先队列)

http://acm.hdu.edu.cn/showproblem.php?pid=1873

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<math.h>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include<set>
#define ll long long
#define inf 0x3f3f3f3f
using namespace std;

struct patient
{
    int id;
    int val;
};

patient p[2005];

bool operator<(patient p1,patient p2)
{
    if(p1.val==p2.val)
        return p1.id>p2.id;
    return p1.val<p2.val;
}
///优先级高的排在前面,重载操作符出来效果和自定义函数相反
priority_queue<patient>que1,que2,que3;


int n;
string s;
int a,b;


int main()
{
    while(cin>>n)
    {
        while(que1.size())
            que1.pop();
        while(que2.size())
            que2.pop();
        while(que3.size())
            que3.pop();
        int cnt=0;
        while(n--)
        {
            cin>>s;
            if( s[0]=='I' )
            {
                cin>>a>>b;///有一个优先级为b的病人要a医生诊治
                cnt++;
                if( a==1 )///丢进a医生得队列
                    que1.push({cnt,b});
                if(a==2)
                    que2.push({cnt,b});
                if(a==3)
                    que3.push({cnt,b});
            }
            else
            {
                cin>>a;///医生a诊断了一个病人,问此人编号,即队列出队
                patient now;
                if(a==1)
                {
                    if(que1.size())
                    {
                        now=que1.top();
                        que1.pop();
                        cout<<now.id<<endl;
                    }
                    else
                        cout<<"EMPTY"<<endl;
                }
                else if(a==2)
                {
                    if(que2.size())
                    {
                        now=que2.top();
                        que2.pop();
                        cout<<now.id<<endl;
                    }
                    else
                        cout<<"EMPTY"<<endl;
                }
                else
                {
                    if(que3.size())
                    {
                        now=que3.top();
                        que3.pop();
                        cout<<now.id<<endl;
                    }
                    else
                        cout<<"EMPTY"<<endl;
                }
            }

        }
    }
    return 0;
}

 

posted @ 2019-08-18 16:32  守林鸟  阅读(187)  评论(0编辑  收藏  举报