Backgammon

Topic

Description

五子棋是一种两人对弈的纯策略型棋类游戏,是世界智力运动会竞技项目之一,通常双方分别使用黑白两色的棋子,下在棋盘直线与横线的交叉点上,先形成5子连线者获胜。

现在希望你编写程序来判断黑方是否已经走投无路,即无论黑方下在何处,白方下一次落子都将获得胜利。为简化题目不考虑斜向的情况,只考虑横与竖。

Input

输入为一个15*15的数组,0表示没有落子,1表示为落了黑子,2表示落了白子。

Output

如果黑棋已经走投无路则输出Yes,否则输出 No。

Sample input

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 1 1 1 0 0 0 0 0 0 0 0 0
0 0 0 2 2 2 2 0 0 0 0 0 0 0 0
0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Sample output

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 1 1 1 0 0 0 0 0 0 0 0 0
0 0 0 2 2 2 2 1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

More info: ACMore

Answer

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
#include <bits\stdc++.h>
using namespace std;
int main()
{
int a[15][15];
int i, i2, i3, i4;
int flag = 0;
int sum = 0;
for (i = 0; i < 15; i++)
for (i2 = 0; i2 < 15; i2++)
scanf("%d", &a[i][i2]);
for (i = 0; i < 15; i++) {
for (i2 = 0; i2 < 15; i2++) {
if (a[i][i2] == 0) {
a[i][i2] = 1;
for (i3 = 0; i3 < 15; i3++) {
for (i4 = 0; i4 < 11; i4++) {
if (a[i3][i4] == 1 &&
a[i3][i4 + 1] == 1 &&
a[i3][i4 + 2] == 1 &&
a[i3][i4 + 3] == 1 &&
a[i3][i4 + 4] == 1) {
flag = 2;
}
}
}
for (i4 = 0; i4 < 15; i4++)
for (i3 = 0; i3 < 11; i3++)
if (a[i3][i4] == 1 &&
a[i3 + 1][i4] == 1 &&
a[i3 + 2][i4] == 1 &&
a[i3 + 3][i4] == 1 &&
a[i3 + 4][i4] == 1)
flag = 2;
if (flag == 2) {
printf("No");
return 0;
}
flag = 0;
a[i][i2] = 2;
for (i3 = 0; i3 < 15; i3++)
for (i4 = 0; i4 < 11; i4++)
if (a[i3][i4] == 2 &&
a[i3][i4 + 1] == 2 &&
a[i3][i4 + 2] == 2 &&
a[i3][i4 + 3] == 2 &&
a[i3][i4 + 4] == 2)
flag = 1;
for (i4 = 0; i4 < 15; i4++)
for (i3 = 0; i3 < 11; i3++)
if (a[i3][i4] == 2 &&
a[i3 + 1][i4] == 2 &&
a[i3 + 2][i4] == 2 &&
a[i3 + 3][i4] == 2 &&
a[i3 + 4][i4] == 2)
flag = 1;
if (flag == 1)
sum++;
a[i][i2] = 0;
}
}
}
if (sum >= 2) {
printf("Yes");
return 0;
}
printf("No");
return 0;
}