HDU OJ 1873 看病要排队(自定义比较器优先队列)


题目链接
自定义优先级队列比较器,捣鼓了半天,其他的没什么难度

#include <bits/stdc++.h>
using namespace std;

struct cmp{
	bool operator() (pair<int, int>&a, pair<int, int>&b){
		if (a.first == b.first)return a.second > b.second;
		return a.first < b.first;
	}
};

int main()
{
	priority_queue<pair<int, int>, vector<pair<int, int> >, cmp> arr[3];
	int n, index, pri;
	string s;
	while (cin >> n)
	{
		int cnt = 1;
		for (int i = 0; i < 3; ++i)while (!arr[i].empty())arr[i].pop();
		for (int i = 0; i < n; ++i)
		{
			cin >> s;
			if (s == "IN"){
				cin >> index >> pri;
				arr[index - 1].push(make_pair(pri, cnt++));
			}else{
				cin >> index;
				if (arr[index - 1].empty())cout << "EMPTY" << endl;
				else{
					cout << arr[index - 1].top().second << endl;
					arr[index - 1].pop();
				}
			}
		}
	}
	return 0;
}
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务