# HOJ 1873 看病要排队（优先级队列 priority_queue, 巨水）

1、定义一个结构体 person 来描述病人的信息，
int enter_id; //进场顺序
int priority; //优先级

2、3个医生，每个医生前面都有一条队列。 模拟医生看病顺序。

``````#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
using namespace std;
const int MaxN = 2010;
int n;
char cmd[10];

struct person
{
int enter_id;	//进场顺序
int priority;	//优先级
bool operator<(const person & rhs) const
{
if(priority != rhs.priority)
return priority < rhs.priority;
return enter_id > rhs.enter_id;
}
};

void solve()
{
priority_queue<person> q[4];
int doctor, priority_id;
person per;
int cnt = 0;
for(int i = 0; i < n; ++i)
{
scanf("%s", cmd);
if(cmd[0] == 'I')
{
scanf("%d%d", &doctor, &priority_id);
per.enter_id = ++cnt, per.priority = priority_id;
q[doctor].push(per);
}else{
scanf("%d", &doctor);
if(!q[doctor].size())
{
printf("EMPTY\n");
}else{
per = q[doctor].top();q[doctor].pop();
printf("%d\n", per.enter_id);
}
}
}
}

int main()
{
while(scanf("%d", &n) != EOF)
{
solve();
}
return 0;
}

/* 7 IN 1 1 IN 1 2 OUT 1 OUT 2 IN 2 1 OUT 2 OUT 1 2 IN 1 1 OUT 1 */

/* 2 EMPTY 3 1 1 */
``````
原文作者：qq_38232157
原文地址: https://blog.csdn.net/qq_38232157/article/details/108309389
本文转自网络文章，转载此文章仅为分享知识，如有侵权，请联系博主进行删除。