Problem description: Waiting for medical treatment. This is common knowledge of people on Earth.
However, after careful observation of 0068, he found that there are still some exquisite queues in the hospital. In 0068 of the hospitals, three doctors (Khan, so few) visited the hospital at the same time. People who see a doctor are in serious condition, so they cannot follow the simple principle of first-come first-served. Therefore, the hospital sets 10 different priorities for each type of illness. The priority of level 10 is the highest, and the priority of level 1 is the lowest. When a doctor sees a doctor, the doctor selects the person with the highest priority in his team for diagnosis and treatment. If you have two patients with the same priority, select the first patient to be queued.
Now, please help the hospital to simulate the process of seeing a doctor.
The input data contains multiple groups of tests. process the data until 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.
Next there are n rows indicating the event.
There are two types of events:
1: "In a B" indicates that a patient with priority B needs to be treated as a doctor. (0 <A <= 3, 0 <B <= 10)
2: "Out A" indicates that Doctor A has performed a diagnosis and treatment. After the diagnosis and treatment, the patient is discharged from hospital. (0 <A <= 3)
Output for each "out a" event, output the ID of the person to be diagnosed in one row. If no patient needs to be diagnosed during the event, "empty" is output ".
The Diagnosis and Treatment person ID is defined as: in a group of tests, when the "in a B" event occurs K times, the incoming patient id is K. Start from 1.
Sample Input
7IN 1 1IN 1 2OUT 1OUT 2IN 2 1OUT 2OUT 12IN 1 1OUT 1
Sample output
2EMPTY311
Authorlinle
Source2008 Zhejiang University Postgraduate review warm-up competition (2) -- Quanzhen Simulation
/********************************** Date: * Author: sjf0115 * question: HDU question 1873: Medical to queue * Source: http://acm.hdu.edu.cn/showproblem.php? PID = 1873 * result: AC * Source: 2008 re-trial warm-up round for Zhejiang University graduate students (2) -- full simulation * conclusion: * *********************************/# include <iostream> # include <stdio. h ># include <queue> using namespace STD; struct patient {// value int priority; // number int key; // overload operator friend bool operator <(patient P1, patient P2) {If (p1.priority! = P2.priority) {return p1.priority <p2.priority;} else {return p1.key> p2.key ;}}; int main () {int I, n, k; char type [4]; int doctorid, patientid; patient [2001]; while (scanf ("% d", & N )! = EOF) {// define three doctors priority_queue <patient> doctor1; priority_queue <patient> doctor2; priority_queue <patient> doctor3; k = 1; while (n --) {scanf ("% s", type); // If (strcmp (type, "in") = 0) {// enter the patient and doctor patient [K]. key = K; scanf ("% d", & doctorid, & patient [K]. priority); // queue if (doctorid = 1) {doctor1.push (patient [k]);} else if (doctorid = 2) {doctor2.push (patient [k]);} else {doctor3.push (patient [k]);} k ++;} // discharged else if (strcmp (type, "out ") = 0) {// The Doctor doctorid performs a diagnosis and treatment. After the diagnosis and treatment, the patient is discharged from the hospital scanf ("% d", & doctorid ); // doctor 1if (doctorid = 1) {If (doctor1.empty () {printf ("Empty \ n");} else {printf ("% d \ n ", doctor1.top (). key); // discharged doctor1.pop () ;}// DOCTOR 2 else if (doctorid = 2) {If (doctor2.empty ()) {printf ("Empty \ n");} else {printf ("% d \ n", doctor2.top (). key); // discharged from hospital doctor2.pop () ;}// DOCTOR 3 else {If (doctor3.empty () {printf ("Empty \ n ");} else {printf ("% d \ n", doctor3.top (). key); // doctor3.pop () ;}}} return 0 ;}
Note: priority queue is used.
If you do not know the priority queue, refer to the blog post: Click to open the link