Hdu1873 queue for medical treatment (priority queue)

Source: Internet
Author: User

Hdu1873 queue for medical treatment (priority queue)

 

Waiting for medical treatment Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission (s): 5488 Accepted Submission (s): 2257



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 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. (0 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 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

Author linle

 

It seems that the priority queue is used as a tool ....

# Include
# Include
# Include
# Include
# Include
Using namespace std;
Struct node {
Friend bool operator <(node n1, node n2)
{
If (n1.priority! = N2.priority)
Return n1.priority Else return n1.value> n2.value;
}
Int priority;
Int value;
};


Int main ()
{
Int n, I, j, k, a, B;
Char str [20];
Node patient [2005];
While (scanf ("% d", & n )! = EOF)
{
K = 1;
Priority_queue Doc1;
Priority_queue Doc2;
Priority_queue Doc3;
For (I = 1; I <= n; I ++)
{
Scanf ("% s", str );
If (strcmp (str, "IN") = 0 ){
Scanf ("% d", & a, & B );
Patient [k]. priority = B;
Patient [k]. value = k;
If (a = 1) doc1.push (patient [k]);
If (a = 2) doc2.push (patient [k]);
If (a = 3) doc3.push (patient [k]);
K ++;
}
If (strcmp (str, "OUT") = 0 ){
Scanf ("% d", & );
If (a = 1 ){
If (doc1.empty () printf ("EMPTY \ n ");
Else {
Printf ("% d \ n", doc1.top (). value );
Doc1.pop ();
}
}
If (a = 2 ){
If (doc2.empty () printf ("EMPTY \ n ");
Else {
Printf ("% d \ n", doc2.top (). value );
Doc2.pop ();
}
}
If (a = 3 ){
If (doc3.empty () printf ("EMPTY \ n ");
Else {
Printf ("% d \ n", doc3.top (). value );
Doc3.pop ();
}
}
}
}
}
Return 0;
}

Related Article

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.