waiting for the doctor to queueTime
limit:3000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 5771 Accepted Submission (s): 2371
problem DescriptionWaiting for the doctor to queue this is the common sense that all 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.
InputThe input data contains multiple sets of tests, please handle 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)
Outputfor each "Out A" event, output 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 Input
7IN 1 1IN 1 2OUT 1OUT 2IN 2 1OUT 2OUT 12IN 1 1OUT 1
Sample Output
2empty311
AuthorLinle
Source2008 Zhejiang University Postgraduate second-round warm-up (2)--Full true simulation
<span style= "FONT-SIZE:14PX;" > #include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include < Queue> #include <algorithm>using namespace Std;char opr[10];struct node{int level;//level int id;//doctor number friend B Ool operator < (node A,node b)//Reload Maximum priority queue {if (a.level==b.level) return a.id>b.id; else return a.level<b.level; }};int Main () {int N; Node hos; while (~SCANF ("%d", &n)) {int count=0; Priority_queue<node>q[4];while (n--) {int doctor,level; scanf ("%s", OPR), if (strcmp (OPR, "in") ==0) {scanf ("%d%d" , &doctor,&level); Hos.level=level; hos.id=++count;//attention to the requirements Q[doctor].push (HOS) in the topic; } else if (strcmp (OPR, "out") ==0) {scanf ("%d", &doctor); if (!q[doctor].empty ()) {node result=q[doctor].top (); Q[doctor].pop (); printf ("%d\n", result.id);} else printf ("empty\n"); }}} return 0;} </span>
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Hdoj 1873 doctor to queue (priority queue utilization)