优先队列 - 初步
7 IN 1 1 IN 1 2 IN A B 其中 A 代表 医生编号, B 代表优先权, 病人按照 1 开始编号,IN 一下,就是进来一个病人 OUT 1 OUT 2
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <algorithm>using std::priority_queue;const int N = 4;
struct Node {int person_id;int weight;friend bool operator< (Node a, Node b) {if (a.weight != b.weight) return a.weight < b.weight;// 重载小于号, 从大到小排return a.person_id > b.person_id; // 重要,贡献两次 WA}
};char ch[N];
int main() {int T;while (scanf("%d", &T) == 1) {priority_queue<Node> Q[N];int a, b, cnt = 0;while (T--) {scanf("%s", ch);if (ch[0] == 'I') {scanf("%d%d", &a, &b);Node tmp;tmp.person_id = ++cnt;tmp.weight = b;Q[a].push(tmp);}else {scanf("%d", &a);if (!Q[a].empty()) {std::cout << Q[a].top().person_id << std::endl;Q[a].pop();}else {printf("EMPTY\n");}}}}return 0;
}