hdu 1873 queuing to see a doctor (priority queue template question)

Portal

Problem Description

This is common sense that everyone on earth knows about waiting in line to see a doctor.
However, after careful observation of 0068, he found that there are still some particularities in queuing in the hospital. The hospital where 0068 went to had three doctors (sweat, so little) seeing a doctor at the same time. The patient's condition is different, so it cannot be based on the simple first-come, first-served principle. Therefore, the hospital has set 10 different priorities for each condition. Level 10 has the highest priority, and level 1 has the lowest priority. When a doctor sees a doctor, he will choose a person with the highest priority in his team for diagnosis and treatment. If two patients with the same priority are encountered, the patient who comes to the queue first is selected.

Now I ask you to help the hospital simulate this process of seeing a doctor.

Input

The input data contains multiple sets of tests, please process to the end of the file.
There is a positive integer N (0<N<2000) in the first row of each group of data to indicate the number of events.
Next, there are N rows respectively representing the events that occurred.
There are two types of events:
1: "IN AB", which means that a patient with priority B requires doctor A to diagnose and treat. (0<A<=3,0<B<=10)
2: "OUT A" means that doctor A performed a diagnosis and treatment. After the diagnosis and treatment, the patient was discharged. (0<A<=3)

Output

For each "OUT A" event, please output the ID of the person being diagnosed in one line. If no patient needs diagnosis and treatment at the time of the event, "EMPTY" is output.
The ID of the patient is defined as: in a set of tests, when the "IN A B" event occurs for the Kth time, the incoming patient ID is K. Numbering starts from 1.

Sample Input

7
IN 1 1
IN 1 2
OUT 1
OUT 2
IN 2 1
OUT 2
OUT 1
2
IN 1 1
OUT 1

Sample Output

2
EMPTY
3
1
1

Code:

#include<bits/stdc++.h>
using namespace std;
struct node{
    
    
	int num;
	int id;
};
bool operator < (const node &x,const node &y){
    
    
	if(x.num==y.num){
    
    
		return x.id > y.id; 
	}
	else{
    
    
		return x.num<y.num;
	}
}
int main()
{
    
    
	int n,a,b;
	string s;
	while(~scanf("%d",&n))
	{
    
    
		int k=1;
		priority_queue<node> q[4];
		while(n--)
		{
    
    
			cin>>s>>a;
			if(s=="IN"){
    
    
				scanf("%d",&b);
				q[a].push({
    
    b,k});
				k++;
			}
			else{
    
    
				if(!q[a].empty()){
    
    
					printf("%d\n",q[a].top().id);
					q[a].pop();
				}
				else{
    
    
					cout<<"EMPTY"<<endl;
				}
			}
		}
	}
	return 0;
}

to sum up:

Priority queue custom priority:

struct node{
    
    
	int num;
	int id;
};
bool operator < (const node &x,const node &y){
    
    
	if(x.num==y.num){
    
    
		return x.id > y.id; //从小到大
	}
	else{
    
    
		return x.num<y.num;//从大到小
	}
}
priority_queue<node> q;

Guess you like

Origin blog.csdn.net/Lzhzl211/article/details/114766850