-
Notifications
You must be signed in to change notification settings - Fork 4
/
12247.cpp
56 lines (49 loc) · 1.06 KB
/
12247.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
#include <iostream>
#include <algorithm>
using namespace std;
int a[3], b[3];
bool allZero() {
for (int i = 0; i < 2; i++) if (a[i] != 0 or b[i] != 0) return false;
return a[2] == 0;
}
bool valid(int num) {
for (int i = 0; i < 2; i++) if (a[i] == num or b[i] == num) return false;
return a[2] != num;
}
bool canWin(int num) {
b[2] = num;
bool taken[3] = { 0, 0, 0 };
int score = 0;
for (int i = 0; i < 3; i++) {
int took = -1;
int best = -1;
for (int j = 0; j < 3; j++) {
if (not taken[j] and a[i] > b[j] and b[j] > best) {
took = j;
best = b[j];
}
}
if (took != -1) {
taken[took] = true;
score++;
} else {
score--;
}
}
return score < 0;
}
int main() {
while (cin >> a[0] >> a[1] >> a[2] >> b[0] >> b[1] and not allZero()) {
// cout << canWin(30) << endl;
bool won = false;
for (int i = 1; i <= 52; i++) {
if (valid(i) and canWin(i)) {
won = true;
cout << i << endl;
break;
}
}
if (not won) cout << -1 << endl;
}
return 0;
}