Waiting for the doctor to queue
Time limit:3000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 5877 Accepted Submission (s): 2417
Problem description to see a doctor in line this is the common sense that the Earth people know.
However, after careful observation of 0068, he found that the hospital lined up or there are fastidious. 0068 hospitals went to the hospital with three doctors (sweat, so little) at the same time to see a doctor. And the doctor's illness has severity, so can not be based on a simple first-served principle. So hospitals prescribe 10 different priorities for each condition. Level 10 has the highest priority and level 1 has the lowest priority. When a doctor is in the hospital, he or she chooses a person with the highest priority in his or her team for treatment. If you encounter two patients with the same priority, select the first patient to queue up.
Now ask you to help the hospital simulate the doctor's procedure.
Input data contains multiple sets of tests, please process to the end of the file.
The first row of each group of data has a positive integer N (0<n<2000) indicating the number of events that occurred.
Next there are n rows representing the events that occurred.
There are two types of events:
1: "In a B", indicates that a patient with priority B requires doctor A to diagnose and treat. (0<a<=3,0<b<=10)
2: "Out A", indicating that doctor A has performed a diagnosis and treatment, the patient is discharged. (0<a<=3)
Output for each "out A" event, print the ID number of the person being diagnosed in a row. If no patient is required to diagnose the event, the output is "EMPTY".
The ID of the person to be diagnosed is defined as: in a set of tests, the "in a B" event occurs k times, the patient ID that comes in is K. Numbering starts from 1.
Sample Input7 in 1 1 in 1 2 out 1 off 2 in 2 1 off 2 out 1 2 in 1 1 out 1
Sample Output2 EMPTY 3 1 1
Authorlinle
Source2008 Zhejiang University Postgraduate second-round warm-up (2)--Full true simulation
Recommendlcy | We have carefully selected several similar problems for you:1871 1872 1876 1875 1874 seriously ill first look first look, but after out the doctor is disorderly appearance, S O~_!_//ac
1#include <queue>2#include <cstdio>3#include <cstring>4#include <stdio.h>5 using namespacestd;6 7 structPatients8 {9 intwant, PRI, id;TenFriendBOOL operator<(Patients want, patients PRI) One { A if(Want.pri = =Pri.pri) - returnWant.id >pri.id; - Else the returnWant.pri < Pri.pri;//* * The larger the number, the greater the priority *s* - } - }; - + intMain () - { + intN; A while(~SCANF ("%d", &N)) at { -Priority_queue <patients> Doctor1;//three physicians, which define three queues; -Priority_queue <patients>Doctor2; -Priority_queue <patients>Doctor3; - intans=0, A, b; - Charko[Ten]; in patients t; - while(n--) to { +scanf"%s", KO); - if(ko[0] =='I') the { *scanf"%d%d", &a, &b); $++ans;Panax Notoginseng if(A = =1)//queue up; - { theT.want =A; +T.pri =b; AT.id =ans; the Doctor1.push (t); + } - if(A = =2) $ { $T.want = A; T.pri = b; T.id =ans; - Doctor2.push (t); - } the if(A = =3) - {WuyiT.want = A; T.pri = b; T.id =ans; the Doctor3.push (t); - } Wu } - Else About { $ intfind; -scanf"%d", &find);//out of the team; - if(Find = =1) - { A if(!doctor1.empty ()) + { thet=doctor1.top (); - Doctor1.pop (); $printf"%d\n", t.id); the } the Else theprintf"empty\n"); the } - if(Find = =2) in { the if(!doctor2.empty ()) the { Aboutt=Doctor2.top (); Doctor2.pop (); theprintf"%d\n", t.id); the } the Else +printf"empty\n"); - } the if(Find = =3)Bayi { the if(!doctor3.empty ()) the { -t=Doctor3.top (); Doctor3.pop (); -printf"%d\n", t.id); the } the Else theprintf"empty\n"); the } - } the } the } the return 0;94}
Hangzhou Electric 1873--To line up the doctor