-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathq2.cpp
59 lines (54 loc) · 1.19 KB
/
q2.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <iostream>
#include <set>
#include <algorithm>
using std::endl;
using std::cin;
using std::cout;
using std::set;
// 2. 双队列
// stl库的set内部有序,所以使用set维护用户队列
// poj通过,但是cousera会compile error
// 具体的,可以手写avl树或者红黑树
struct User {
int id = 0;
int priority = 0;
User(int x, int y) :id(x), priority(y) {}
bool operator< (const User &user) const{
return priority < user.priority;
}
bool operator== (const User &user) const{
return priority == user.priority;
}
};
int main(int argc, char *argv[]) {
set<User> users;
int order = 0, k = 0, p = 0;
while (cin >> order && order) {
if (order == 1) {
cin >> k >> p;
User user(k, p);
auto search = users.find(user);
if (search != users.end()) {
users.erase(search);
}
users.insert(user);
} else if (order == 2) {
if (users.empty()) {
cout << 0 << endl;
} else {
auto word = users.end();
word--;
cout << word->id << endl;
users.erase(word);
}
} else if (order == 3) {
if (users.empty()) {
cout << 0 << endl;
} else {
cout << users.begin()->id << endl;
users.erase(users.begin());
}
}
}
return 0;
}