看病要排隊 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<iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <functional>
#include <ctime>
#include <iomanip>
#include <sstream>
#include <algorithm>
#define ll long long
#define PI acos(-1)
#define mes(x,y) memset(x,y,sizeof(x))
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
const ll INF = 1e9 + 10;
ll n, m, k, i, j, x, y;
string s;
struct node {
	ll grade, id;
	node(ll x,ll y):grade(x),id(y){}
	friend bool operator < (node n1, node n2) {
		if (n1.grade == n2.grade)return n1.id > n2.id;
		return n1.grade < n2.grade;
	}
};
int main() {
	FAST_IO;
	while (cin >> n) {
		priority_queue<node>que[5];
		m = 1;
		while (n--) {
			cin >> s;
			if (s == "IN") {
				cin >> x >> y;
				que[x].push(node(y, m++));
			}
			else {
				cin >> x;
				if (que[x].empty()) {
					cout << "EMPTY" << endl;
					continue;
				}
				cout << que[x].top().id << endl;
				que[x].pop();
			}
		}
	}
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章