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;
}
阿里云成长空间 794人发布