-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path12886.cpp
85 lines (82 loc) · 1.98 KB
/
12886.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <iostream>
#include <queue>
using namespace std;
bool check[2001][2001];
struct stone {
int a, b, c;
};
int main() {
int a, b, c;
bool flag = false;
cin >> a >> b >> c;
check[a][b] = true;
check[b][a] = true;
check[b][c] = true;
check[c][b] = true;
check[a][c] = true;
check[c][a] = true;
queue<stone> q;
q.push({a, b, c});
while (!q.empty()) {
int a = q.front().a;
int b = q.front().b;
int c = q.front().c;
q.pop();
if (a == b && b == c) {
flag = true;
break;
}
if (a < b) {
int small = a + a;
int big = b - a;
if (!check[small][big]) {
check[small][big] = true;
q.push({small, big, c});
}
}
if (a > b) {
int small = b + b;
int big = a - b;
if (!check[big][small]) {
check[big][small] = true;
q.push({big, small, c});
}
}
if (a < c) {
int small = a + a;
int big = c - a;
if (!check[small][big]) {
check[small][big] = true;
q.push({small, b, big});
}
}
if (a > c) {
int small = c + c;
int big = a - c;
if (!check[big][small]) {
check[big][small] = true;
q.push({big, b, small});
}
}
if (b < c) {
int small = b + b;
int big = c - b;
if (!check[small][big]) {
check[small][big] = true;
q.push({a, small, big});
}
}
if (b > c) {
int small = c + c;
int big = b - c;
if (!check[big][small]) {
check[big][small] = true;
q.push({a, big, small});
}
}
}
if (flag)
cout << "1\n";
else
cout << "0\n";
}