HDU 1873 看病要排队

来源:互联网 发布:sqlplus连接远程数据库 编辑:程序博客网 时间:2024/05/16 10:31

题目地址:点击打开链接

思路:注意每次把队列清空就行

AC代码:

#include <iostream>#include <queue>using namespace std;struct doctor{    int priority;    int num;    bool operator < (const doctor & x) const    {        if(priority != x.priority)            return priority < x.priority; //最大值优先        else            return num > x.num;//最小值优先    }};int main(){    priority_queue<doctor> pq1,pq2,pq3;    string s;    doctor in,out;    int n,i;    int a,b,k;    while(cin>>n)    {        while(!pq1.empty())//注意是while不是if            pq1.pop();        while(!pq2.empty())            pq2.pop();        while(!pq3.empty())            pq3.pop();        k = 1;        for(i=0; i<n; i++)        {            cin>>s;            if(s == "IN")            {                cin>>a>>b;                in.priority = b;                in.num = k++;                if(a == 1)                {                    pq1.push(in);                }                else if(a == 2)                {                    pq2.push(in);                }                else                {                    pq3.push(in);                }            }            else            {                cin>>a;                if(a == 1)                {                    if(pq1.empty())                        cout<<"EMPTY"<<endl;                    else                    {                        out = pq1.top();                        pq1.pop();                        cout<<out.num<<endl;                    }                }                if(a == 2)                {                    if(pq2.empty())                        cout<<"EMPTY"<<endl;                    else                    {                        out = pq2.top();                        pq2.pop();                        cout<<out.num<<endl;                    }                }                if(a == 3)                {                    if(pq3.empty())                        cout<<"EMPTY"<<endl;                    else                    {                        out = pq3.top();                        pq3.pop();                        cout<<out.num<<endl;                    }                }            }        }    }    return 0;}


0 0