【杭电】[1873]看病要排队

文章字数:183

问题描述

问题分析

优先队列的简单运用
priority_queue<node>q[4];
也就是通过建立一个node包含有逻辑判断的结构体类型的优先队列,在模拟看病排队的过程

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include<stdio.h>
#include<queue>
using namespace std;
struct node {
	int num,lv;
	bool friend operator<(node a,node b) {
		if (a.lv==b.lv)
			return a.num>b.num;
		else
			return a.lv<b.lv;
	}
} a;
int main() {
	int n;
	while(scanf("%d",&n)!=EOF) {
		priority_queue<node>q[4];
		char s[5];
		int t,cnt=0;
		while(n--) {
			scanf("%s",s);
			if(s[0]=='I') {
				scanf("%d %d",&t,&a.lv);
				a.num=++cnt;
				q[t].push(a);
			} else {
				scanf("%d",&t);
				if(q[t].empty())
					printf("EMPTY\n");
				else {
					a=q[t].top();
					printf("%d\n",a.num);
					q[t].pop();
				}
			}
		}
	}
	return 0;
}

题目地址: 【杭电】[1873]看病要排队

该内容采用 CC BY-NC-SA 4.0 许可协议。

如果对您有帮助或存在意见建议,欢迎在下方评论交流。

加载中...