HDU-1873 to wait for a doctor

Source: Internet
Author: User

http://acm.hdu.edu.cn/showproblem.php?pid=1873 to wait for a doctor

Time limit:3000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 5424 Accepted Submission (s): 2225


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 input7in 1 1IN 1 2OUT 1OUT 2IN 2 1OUT 2OUT 12IN 1 1OUT 1

Sample output2empty311

Authorlinle
#include <iostream>#include<cstdio>#include<cstring>#include<queue>using namespacestd;structnode{friendBOOL operator<(node N1,node n2) {if(n1.priority==n2.priority)returnN1.id>n2.id; Else            returnn1.priority<n2.priority; }  intID; intPriority ;};intMain () {intT;  while(~SCANF ("%d",&t)) {inti,a,b,k=1; Chars[5]; Priority_queue<node>Q1; Priority_queue<node>Q2; Priority_queue<node>Q3; structnode p;  while(t--) {scanf ("%s", s); if(s[0]=='I') {scanf ("%d%d",&a,&b); if(a==1) {p.id=k++; P.priority=b;             Q1.push (P); }             if(a==2) {p.id=k++; P.priority=b;             Q2.push (P); }             if(a==3) {p.id=k++; P.priority=b;             Q3.push (P); }         }         if(s[0]=='O') {scanf ("%d",&a); if(a==1)            {                if(!Q1.empty ()) {P=Q1.top (); printf ("%d\n", p.id);                Q1.pop (); }                Elseprintf ("empty\n"); }             if(a==2)            {                if(!Q2.empty ()) {P=Q2.top (); printf ("%d\n", p.id);                Q2.pop (); }                Elseprintf ("empty\n"); }             if(a==3)            {                if(!Q3.empty ()) {P=Q3.top (); printf ("%d\n", p.id);                Q3.pop (); }                Elseprintf ("empty\n"); }         }      }    }   return 0;}

HDU-1873 to wait for a doctor

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.