『codeforces 825b』five Solution

题目链接: 点我

B. Five-In-a-Row
time limit per test :1 second
memory limit per test :256 megabytes
Description
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts.

In current match they have made some turns and now it’s Alice’s turn. She wonders if she can put cross in such empty cell that she wins immediately.

Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal.

Input
You are given matrix 10 × 10 (10 lines of 10 characters each) with capital Latin letters ‘X’ being a cross, letters ‘O’ being a nought and ‘.’ being an empty cell. The number of ‘X’ cells is equal to the number of ‘O’ cells and there is at least one of each type. There is at least one empty cell.

It is guaranteed that in the current arrangement nobody has still won.

Output
Print YES if it’s possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print NO.

Examples
input1

1
2
3
4
5
6
7
8
9
10
XX.XX.....
.....OOOO.
..........
..........
..........
..........
..........
..........
..........
..........

output1
YES

input2

1
2
3
4
5
6
7
8
9
OO.O......
..........
..........
..........
..........
..........
..........
..........
..........

output2
NO

Solution

直接模拟,不多解释,你懂的

AC 31ms

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

#include <cstdio>
#include <cstring>
#define chk if (num >= 5) return true;
using namespace std;
char M[12][12];
inline char ()
{
char t = getchar();
while (t != '.' && t != 'O' && t != 'X') t = getchar();
return t;
}
inline int checkwin(const int &x, const int &y)
{
int xx = x, yy = y;

int num = 0;
while (M[xx][y] == 'X') xx--, num++;
xx = x + 1;
while (M[xx][y] == 'X') xx++, num++;
chk

//vertical
num = 0;
while (M[x][yy] == 'X') yy--, num++;
yy = y + 1;
while (M[x][yy] == 'X') yy++, num++;
chk

xx = x, yy = y, num = 0;
//case 1
while (M[xx][yy] == 'X') xx--, yy--, num++;
xx = x + 1, yy = y + 1;
while (M[xx][yy] == 'X') xx++, yy++, num++;
chk
//case 2
xx = x, yy = y, num = 0;
while (M[xx][yy] == 'X') xx++, yy--, num++;
xx = x - 1, yy = y + 1;
while (M[xx][yy] == 'X') xx--, yy++, num++;
chk

return false;
}
int main(int argc, char **argv)
{
for (int i = 1; i <= 10; i++)
for (int j = 1; j <= 10; j++)
M[i][j] = getch();
for (int i = 1; i <= 10; i++)
for (int j = 1; j <= 10; j++)
{
if (M[i][j] == '.')
{
M[i][j] = 'X';
if (checkwin(i, j))
{
puts("YES");
return 0;
}
M[i][j] = '.';
}
}
puts("NO");
return 0;
}