HDU 1873 is waiting for medical treatment

Source: Internet
Author: User

HDU 1873 is waiting for medical treatment
Too many Problem Description to queue for medical treatment. This is common knowledge of everyone 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 data group has a positive integer N (0 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. (02: "out a" indicates that Doctor A has performed A diagnosis and treatment. After the diagnosis and treatment, the patient is discharged from hospital. (0Output 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

Angry AC .. It took 80 minutes .. The key point is to store the input in array and put it into the queue. The difficulty is that the number of the person who sees the doctor is different each time, and the priority is not good. For example, if 1 and 2 have a higher priority than 2 and 2, but the output of out 1 is actually 1, it will become null. My practice is to get two queues, clear one queue, and put the cleared ones in another queue for storage. If conditions are met, do not save them. Then, the elements of another queue are placed in the first queue. This ensures that the optimal solution is found every time.
# Include
 
  
# Include
  
   
# Include
   
    
# Include using namespace std; struct node {int haoma; int bianhao; int sum; friend bool operator <(node a, node B) {if (a. sum! = B. sum) return a. sum
    
     
B. bianhao; // small high priority }}; int main () {char s [55]; priority_queue
     
      
Q; priority_queue
      
        Q; int t; node st, ed; node f [2500]; while (scanf ("% d", & t )! = EOF) {int I = 1; int ans; int sss = 1; while (t --) {scanf ("% s", s ); if (s [0] = 'I') {scanf ("% d", & f [I]. haoma, & f [I]. sum); f [I]. bianhao = sss; ed. bianhao = f [I]. bianhao; ed. haoma = f [I]. haoma; ed. sum = f [I]. sum; I ++; sss ++; q. push (ed); // here, the input is stored in an array and put into the queue .} Else {int flag = 1; scanf ("% d", & ans); while (! Q. empty () {st = q. top (); q. pop (); if (ans = st. haoma) {printf ("% d \ n", st. bianhao); // directly output the desired output and then jump out. Flag = 0; break;} Q. push (st); // put it in another queue} if (flag) printf ("EMPTY \ n"); while (! Q. empty () {ed = Q. top (); q. push (ed); // put another queue to the first queue Q. pop () ;}}while (! Q. empty () q. pop ();} return 0 ;}
      
     
    
   
  
 


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.