-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path백준-돌 그룹.cpp.txt
90 lines (82 loc) · 1.54 KB
/
백준-돌 그룹.cpp.txt
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
86
87
88
89
90
#include <iostream>
#include<queue>
#include<utility>
#include<map>
using namespace std;
map<tuple<int, int, int>, int> m;
int main()
{
int A, B, C;
cin >> A >> B >> C;
m[make_tuple(A, B, C)] = 1;
queue<tuple<int, int, int>> q;
q.push(make_tuple(A, B, C));
bool game_end = false;
tuple<int, int, int> t;
while (!q.empty())
{
t = q.front();
q.pop();
A = get<0>(t);
B = get<1>(t);
C = get<2>(t);
//cout << A << " " << B << " " << C << endl;
if (A == B && B == C)
{
cout << "1" << endl;
game_end = true;
break;
}
if (A < B)
{
if (m.count(make_tuple(A + A, B - A, C)) == 0)
{
m[make_tuple(A + A, B - A, C)] = 1;
q.push(make_tuple(A + A, B - A, C));
}
}
else if(B<A)
{
if (m.count(make_tuple(A -B, B +B, C)) == 0)
{
m[make_tuple(A -B, B+B, C)] = 1;
q.push(make_tuple(A - B, B + B, C));
}
}
if (A < C)
{
if (m.count(make_tuple(A + A, B, C-A)) == 0)
{
m[make_tuple(A + A, B, C - A)] = 1;
q.push(make_tuple(A + A, B, C - A));
}
}
else if(C<A)
{
if (m.count(make_tuple(A - C, B, C+C)) == 0)
{
m[make_tuple(A - C, B, C + C)] = 1;
q.push(make_tuple(A - C, B, C + C));
}
}
if (B < C)
{
if (m.count(make_tuple(A, B +B, C-B)) == 0)
{
m[make_tuple(A, B + B, C - B)] = 1;
q.push(make_tuple(A, B + B, C - B));
}
}
else if(B>C)
{
if (m.count(make_tuple(A, B -C, C +C)) == 0)
{
m[make_tuple(A, B - C, C + C)] = 1;
q.push(make_tuple(A, B - C, C + C));
}
}
}
if (!game_end)
cout << "0" << endl;
return 0;
}