Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission (s): 3672 Accepted Submission (s): 1485
Problem Description
Waiting for medical treatment is a common sense that everyone on Earth knows.
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.
Input
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.
Idea: it is easier to use priority queues, but note that priority queues are implemented by heap and are not sorted stably.
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
[Cpp]
# Include <iostream>
# Include <cstdio>
# Include <cstring>
# Include <algorithm>
# Include <queue> using namespace std; // Accepted 1873 156 MS 328 K
C ++ Achiberx struct node {int id;
Int p; // priority;
Bool operator <(const node & a) const {
If (a. p = p) return a. id <id;
Else {
Return a. p> p ;}}};
Priority_queue <node> Q1, Q2, Q3;
Char mark [5]; int index = 1;
Void init () {index = 1;
Memset (mark, '0', sizeof (mark ));
While (! Q1.empty () Q1.pop ();
While (! Q2.empty () Q2.pop ();
While (! Q3.empty () Q3.pop ();
} Int main () {int n;
Int p, d; // priority, doctor; node tmp;
While (scanf ("% d", & n )! = EOF) {init ();
For (int I = 0; I <n; I ++) {scanf ("% s", mark );
If (mark [0] = 'I') {scanf ("% d", & d, & p );
Tmp. id = index ++;
Tmp. p = p;
If (d = 1) {Q1.push (tmp );
Continue;} if (d = 2) {Q2.push (tmp );
Continue;
} If (d = 3) {Q3.push (tmp );
Continue ;}} else {int res; // result bool flag = false; // is queue empty? Scanf ("% d", & d); if (d = 1) {if (! Q1.empty () {flag = true;
Tmp = Q1.top ();
Q1.pop ();
Res = tmp. id ;}}if (d = 2) {if (! Q2.empty () {flag = true; tmp = Q2.top (); Q2.pop ();
Res = tmp. id ;}}if (d = 3) {if (! Q3.empty () {flag = true;
Tmp = Q3.top (); Q3.pop ();
Res = tmp. id;
} If (flag) {cout <res <endl;} else {cout <"EMPTY" <endl;
}}} Init ();} return 0 ;}