看病要排队

看病要排队

Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 76 Accepted Submission(s): 54
 
Problem 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
 
Author
linle
 
Source
2008浙大研究生复试热身赛(2)——全真模拟
 
Recommend
lcy
/*
题意:模拟一下进栈出栈,每个医生都会有病人,每个病人有对应的给他治病的医生,并且有优先级,
    每个医生先给优先级高的病人治病,如果优先级相同就按照进来的时间顺序进行排队。
初步思路:最多三个医生嘛,每个医生用一个优先队列进行表示,然后每次都取最上面的给他治病,然后出栈就行了

感悟:经历了昨晚的蒙蔽,终于正常了,1Y
*/
#include<bits/stdc++.h>
using namespace std;
struct node{
    int id;
    int rank;
    int time;
    node(){}
    node(int a,int b,int c){
        id=a;
        rank=b;
        time=c;
    }
    bool operator < (const node & other) const{
        if(rank!=other.rank) 
            return rank<other.rank;
        return time>other.time;
    }
};
priority_queue<node> Doctor_1;
priority_queue<node> Doctor_2;
priority_queue<node> Doctor_3;
int n;
string op;
int A,B;
int len1,len2,len3;
int times=1;
void init(){
    while(!Doctor_1.empty()) Doctor_1.pop();
    while(!Doctor_2.empty()) Doctor_2.pop();
    while(!Doctor_3.empty()) Doctor_3.pop();
    len1=len2=len3=0;
    times=1;
}
int main(){
    //freopen("in.txt","r",stdin);
    while(scanf("%d",&n)!=EOF){
        init();
        for(int i=0;i<n;i++){
            cin>>op;
            if(op=="IN"){
                scanf("%d%d",&A,&B);
                switch(A){
                    case 1:Doctor_1.push(node(times++,B,len1++));break;
                    case 2:Doctor_2.push(node(times++,B,len2++));break;
                    case 3:Doctor_3.push(node(times++,B,len3++));break;
                }
            }else{
                scanf("%d",&A);
                switch(A){
                    case 1:
                        if(Doctor_1.empty()) printf("EMPTY
");
                        else{
                            printf("%d
",Doctor_1.top().id);
                            Doctor_1.pop();
                        }
                        ;break;
                    case 2:
                        if(Doctor_2.empty()) printf("EMPTY
");
                        else{
                            printf("%d
",Doctor_2.top().id);
                            Doctor_2.pop();
                        }
                        break;
                    case 3:
                        if(Doctor_3.empty()) printf("EMPTY
");
                        else{
                            printf("%d
",Doctor_3.top().id);
                            Doctor_3.pop();
                        }
                        break;
                }
            }
        }
    }
    return 0;
}
原文地址:https://www.cnblogs.com/wuwangchuxin0924/p/6365669.html