看病要排队
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5877 Accepted Submission(s): 2417
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
Recommend
lcy | We have carefully selected several similar problems for you:
病重的先看, 同样地先来的先看, 但OUT 后医生是无序出现的, So~_!_
//AC
1 #include2 #include 3 #include 4 #include 5 using namespace std; 6 7 struct patients 8 { 9 int want, pri, id;10 friend bool operator < (patients want, patients pri)11 {12 if(want.pri == pri.pri)13 return want.id > pri.id; 14 else15 return want.pri < pri.pri; //**数越大, 优先级越大*s* 16 } 17 };18 19 int main()20 {21 int n;22 while(~scanf("%d", &n))23 {24 priority_queue doctor1; //三个医生, 定义三个队列;同时清空队列。; 25 priority_queue doctor2;26 priority_queue doctor3;27 int ans=0, a, b;28 char ko[10];29 patients t;30 while(n--)31 {32 scanf("%s", ko);33 if(ko[0] == 'I')34 {35 scanf("%d %d", &a, &b);36 ++ans;37 if(a == 1) //入队 ; 38 {39 t.want = a;40 t.pri = b;41 t.id = ans;42 doctor1.push(t); 43 }44 if(a == 2)45 {46 t.want = a; t.pri = b; t.id = ans;47 doctor2.push(t); 48 }49 if(a == 3)50 {51 t.want = a; t.pri = b; t.id = ans;52 doctor3.push(t); 53 }54 }55 else56 {57 int find;58 scanf("%d", &find); //出队; 59 if(find == 1)60 {61 if(!doctor1.empty())62 {63 t=doctor1.top();64 doctor1.pop();65 printf("%d\n",t.id);66 }67 else68 printf("EMPTY\n");69 }70 if(find == 2)71 {72 if(!doctor2.empty())73 {74 t=doctor2.top(); doctor2.pop();75 printf("%d\n",t.id);76 }77 else78 printf("EMPTY\n");79 } 80 if(find == 3)81 {82 if(!doctor3.empty())83 {84 t=doctor3.top(); doctor3.pop();85 printf("%d\n",t.id);86 }87 else88 printf("EMPTY\n");89 }90 }91 }92 }93 return 0;94 }