看病要排队 HDU - 1873 题解

题目

看病要排队这个是地球人都知道的常识。
不过经过细心的0068的观察,他发现了医院里排队还是有讲究的。0068所去的医院有三个医生(汗,这么少)同时看病。而看病的人病情有轻重,所以不能根据简单的先来先服务的原则。所以医院对每种病情规定了10种不同的优先级。级别为10的优先权最高,级别为1的优先权最低。医生在看病时,则会在他的队伍里面选择一个优先权最高的人进行诊治。如果遇到两个优先权一样的病人的话,则选择最早来排队的病人。

现在就请你帮助医院模拟这个看病过程。

Input

输入数据包含多组测试,请处理到文件结束。
每组数据第一行有一个正整数N(0<N<2000)表示发生事件的数目。
接下来有N行分别表示发生的事件。
一共有两种事件:
1:“IN A B”,表示有一个拥有优先级B的病人要求医生A诊治。(0<A<=3,0<B<=10)
2:“OUT A”,表示医生A进行了一次诊治,诊治完毕后,病人出院。(0<A<=3)

Output

对于每个"OUT A"事件,请在一行里面输出被诊治人的编号ID。如果该事件时无病人需要诊治,则输出"EMPTY"。
诊治人的编号ID的定义为:在一组测试中,"IN A B"事件发生第K次时,进来的病人ID即为K。从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

思路

定义一个优先队列然后模拟

代码

#include"bits/stdc++.h"
using namespace std;
struct sq{//记录一下病人的id
	int num ,id;
};
bool operator<(const sq &x, const sq &y){//重载小于号,适用于优先队列的排序规则
	if(x.num==y.num)
		return x.id>y.id;
	else
		return x.num<y.num;
}
int main(){
	int n;
	while(cin>>n){
		int d, k=1;
		priority_queue<sq>s[4];
		while(n--){
			string a;
			sq custom;
			cin>>a>>d;
			if(a=="IN"){
				custom.id=k++;
				cin>>custom.num;
				s[d].push(custom);
			}
			else if(a=="OUT"){
				if(s[d].empty())cout<<"EMPTY"<<endl;
				else {
					custom=s[d].top();
					s[d].pop();
					cout<<custom.id<<endl;
				}
			}
	}
	}
	
}
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
//活期储蓄处理中,储户开户、销户、存入、支出活动频繁,系统设计要求: //1)能比较迅速地找到储户的帐户,以实现存款、取款记账; //2)能比较简单,迅速地实现插入和删除,以实现开户和销户的需要。 #include #include #include using namespace std; int total; //初始时银行现存资金总额 int closeTime; //营业结束时间 int arriveTime; //两个到达事件之间的间隔上限 int dealTime; //客户之间交易的时间上限 int dealMoney = 30000; //交易额上限 int currentTime = 0; //当前时间 int totalTime = 0; //客户逗留总时间 int counter = 0; //客户总数 int number = 1; //初始客户序列号+ struct service { int num; //客户号 string type; //到达或离开 int beginTime; int endTime; int money; //正数为存款,负数为取款 service* next; }; struct queue { //队列 service* head; service* rear; }; void push(queue &q,int d) {// 插入元素d为Q的新的队尾元素 service* temp = new service; temp->money = d; temp->next = NULL; if(NULL == q.head) {//队列为空,初始化 q. head = temp; q. rear = temp; }//if else {//队列不为空,插入元素d q. rear->next = temp; q. rear = q.rear->next; }//else } void pop(queue &q) {// 若队列不空,出对列函数 service* temp; temp = q. head; if(NULL ==q. head->next) q.head = q. rear =NULL; else q. head=q. head->next; delete temp; } service* front(queue &q) {//返回队首元素 return q. head; } service* back(queue &q) {//返回队尾元素 return q. rear; } service* searchAndDel(queue &q,int m) {//在队列中寻找可处理元素 service* sign = q. head; //标记头节点 service* temp; while(NULL != q. head) { if((-(q. head->money)) next; // 首节点后移一位,返回原首节点 return temp; // 开办.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include "stdlib.h" #include "string.h" #include "ctype.h" #include #include /* ---------------- */ void apply(); /* 申请帐号 */ void land(); /* 登陆系统 */ void finds(); /* 查询存款 */ void saving(); /* 存钱 */ void get(); /* 取款 */ void turn(); /* 转帐 */ /* --------------------- */ struct per { char name[20]; char accounts[20]; char password[20]; int money; }dat,temp; /* ----------- */ void manage() /* 主函
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值