C-priority queue Entry 1
Time limit:1000 ms
Memory limit:32768kb
64bit Io format:% I64d & % i64usubmit status practice HDU 1873
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.
Sample Input
7IN 1 1IN 1 2OUT 1OUT 2IN 2 1OUT 2OUT 12IN 1 1OUT 1
Sample output
2EMPTY311
STL implements priority queue
Usage:
Header file:
# Include <queue>
Declaration method:
Priority_queue <int> q;
Struct declaration method:
<Span style = "font-size: 12px;"> struct node {int X, Y; friend bool operator <(node A, Node B) {return. x> B. x; // In the struct, the priority of X is high. }}; </span>
Priority_queue <node> q; // define a method
// In this structure, Y is the value, and X is the priority.
// Compare the priority of an element using the custom operator <operator.
Basic operations:
Empty () returns true if the queue is empty
Pop () deletes the peer Element
Push () to add an element
Size () returns the number of elements in the priority queue.
Top () returns the top-to-top element of the priority queue.
In the default priority queue, a queue with a higher priority is displayed first.
In this question, "If two patients with the same priority are met, the first patient will be selected". Therefore, when determining the priority, apart from the priority value, you also need to check the patient id ),
The Code is as follows:
struct hos{int ran,id;friend bool operator <(hos a,hos b){if(a.ran==b.ran)return a.id>b.id;return a.ran<b.ran;}}
There is nothing to say. The full template question. The full code for this question is as follows:
# Include <stdio. h> # include <string. h ># include <queue> using namespace STD; // This sentence is awesome. It's not enough. struct hos {int ran, ID; friend bool operator <(hos, hos B) {if (. ran = B. ran) return. id> B. ID; return. ran <B. ran ;}} t; int main () {int N, K, a, B; char s [5]; while (scanf ("% d", & N )! = EOF) {k = 1; priority_queue