-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2615.cpp
More file actions
203 lines (194 loc) · 2.76 KB
/
2615.cpp
File metadata and controls
203 lines (194 loc) · 2.76 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
// 2615. 오목
// 2019.05.20
// BFS
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int map[21][21];
int dx[8] = { 1,-1,0,0,1,-1,1,-1 };
int dy[8] = { 0,0,1,-1,-1,1,1,-1 };
bool flag1;
bool flag2;
vector<pair<int, int>> v;
bool compare(pair<int, int>& a, pair<int, int>& b)
{
if (a.second == b.second)
{
return a.first < b.first;
}
return a.second < b.second;
}
// 5개 연속으로 놓인것 찾기
void Find(int x, int y, int type)
{
#pragma region 상하
int k = 1;
v.clear();
v.push_back({ x,y });
for (int i = 0; i < 2; i++)
{
int xx = x;
int yy = y;
while (1)
{
xx += dx[i];
yy += dy[i];
if (xx < 1 || yy < 1 || xx>19 || yy>19 || map[xx][yy] != type)
{
break;
}
v.push_back({ xx,yy });
k++;
}
}
if (k == 5)
{
if (type == 1)
{
flag1 = true;
}
else
{
flag2 = true;
}
return;
}
#pragma endregion
#pragma region 좌우
k = 1;
v.clear();
v.push_back({ x,y });
for (int i = 2; i < 4; i++)
{
int xx = x;
int yy = y;
while (1)
{
xx += dx[i];
yy += dy[i];
if (xx < 1 || yy < 1 || xx>19 || yy>19 || map[xx][yy] != type)
{
break;
}
v.push_back({ xx,yy });
k++;
}
}
if (k == 5)
{
if (type == 1)
{
flag1 = true;
}
else
{
flag2 = true;
}
return;
}
#pragma endregion
#pragma region 우상대각
k = 1;
v.clear();
v.push_back({ x,y });
for (int i = 4; i < 6; i++)
{
int xx = x;
int yy = y;
while (1)
{
xx += dx[i];
yy += dy[i];
if (xx < 1 || yy < 1 || xx>19 || yy>19 || map[xx][yy] != type)
{
break;
}
v.push_back({ xx,yy });
k++;
}
}
if (k == 5)
{
if (type == 1)
{
flag1 = true;
}
else
{
flag2 = true;
}
return;
}
#pragma endregion
#pragma region 우하대각
k = 1;
v.clear();
v.push_back({ x,y });
for (int i = 6; i < 8; i++)
{
int xx = x;
int yy = y;
while (1)
{
xx += dx[i];
yy += dy[i];
if (xx < 1 || yy < 1 || xx>19 || yy>19 || map[xx][yy] != type)
{
break;
}
v.push_back({ xx,yy });
k++;
}
}
if (k == 5)
{
if (type == 1)
{
flag1 = true;
}
else
{
flag2 = true;
}
return;
}
#pragma endregion
}
int main()
{
for (int i = 1; i <= 19; i++)
{
for (int j = 1; j <= 19; j++)
{
cin >> map[i][j];
}
}
for (int i = 1; i <= 19; i++)
{
for (int j = 1; j <= 19; j++)
{
if (map[i][j] != 0)
{
Find(i, j, map[i][j]);
if (flag1)
{
cout << 1 << endl;
sort(v.begin(), v.end(), compare);
cout << v[0].first << " " << v[0].second << endl;
return 0;
}
if (flag2)
{
cout << 2 << endl;
sort(v.begin(), v.end(), compare);
cout << v[0].first << " " << v[0].second << endl;
return 0;
}
}
}
}
// 승부가 나지 않았을때
cout << 0 << endl;
return 0;
}