hdu 1873

题意:有n个人去三个医生处排队。每个人病情不一样,病情重的先看,如果病情相同则先来后到。

题解:用一个结构体的优先队列,病情优先,病情相同则序号优先。

 

代码:

#include<iostream>
#include<functional>
#include<queue>
#include <string>
using namespace std;
struct
node
{

    friend
bool operator< (node n1, node n2)
    {

        if
(n1.priority==n2.priority
        {
 
            return
n1.id>n2.id; //以bh小的优先
        } 
        return
n1.priority<n2.priority;
    }

    int
priority;
    int
id;
}
nd1,nd2,nd3;
int
main(){
    int
n;
    while
(scanf("%d",&n)!=EOF){
        priority_queue<node> q1,q2,q3;
        int
tot=1;
        for
(int i=1;i<=n;i++){
            string a;
            cin>>a;
            if
(a=="IN"){
                int
x;
                scanf("%d",&x);
                if
(x==1){
                    scanf("%d",&nd1.priority);
                    nd1.id=tot;
                    q1.push(nd1);
                }

                else if
(x==2){
                    scanf("%d",&nd2.priority);
                    nd2.id=tot;
                    q2.push(nd2);
                }

                else if
(x==3){
                    scanf("%d",&nd3.priority);
                    nd3.id=tot;
                    q3.push(nd3);
                }

                tot++;
            }

            else
{
                int
u;
                scanf("%d",&u);
                if
(u==1){
                    if
(!q1.empty()){
                        printf("%d\n",q1.top().id);
                        q1.pop();
                    }

                    else
printf("EMPTY\n");
                }

                else if
(u==2){
                    if
(!q2.empty()){
                        printf("%d\n",q2.top().id);
                        q2.pop();
                    }

                    else
printf("EMPTY\n");
                }

                else
{
                    if
(!q3.empty()){
                        printf("%d\n",q3.top().id);
                        q3.pop();
                    }

                    else
printf("EMPTY\n");
                }
            }
        }
       
       
    }

    return
0;
}

posted @ 2017-08-21 13:29  LMissher  阅读(216)  评论(0)    收藏  举报