CodeForces - 825B Five-In-a-Row

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'.

Example

Input
XX.XX.....
.....OOOO.
..........
..........
..........
..........
..........
..........
..........
..........
Output
YES
Input
XXOXX.....
OO.O......
..........
..........
..........
..........
..........
..........
..........
..........
Output
NO
五子棋玟是否X再走一步可以获胜。对于每一个没有落子的点查看是否满足。
 1 #include<iostream>
 2 #include<stdio.h>
 3 
 4 using namespace std;
 5 
 6 char c[12][12];
 7 bool flag=false;
 8 
 9 bool check(int a,int b)
10 {
11     int low=a-1,hign=a+1,s=1;
12     for(int i=1;i<=10;i++)
13     {
14         if(low>0&&c[low][b]=='X')
15             low--;
16         if(hign<=10&&c[hign][b]=='X')
17             hign++;
18     }
19     if(hign-low>5)
20         return true;
21     low=b-1;
22     hign=b+1;
23     for(int i=1;i<=10;i++)
24     {
25         if(low>0&&c[a][low]=='X')
26             low--;
27         if(hign<=10&&c[a][hign]=='X')
28             hign++;
29     }
30     if(hign-low>5)
31         return true;
32     low=b-1;
33     hign=b+1;
34     for(int i=1;i<=10;i++)
35     {
36         if(low>0&&c[a-(b-low)][low]=='X'&&(a-(b-low))>0)
37             low--;
38         if(hign<=10&&c[a+(hign-b)][hign]=='X'&&(a+(hign-b))<=10)
39             hign++;
40     }
41     if(hign-low>5)
42         return true;
43     low=b-1;
44     hign=b+1;
45     for(int i=1;i<=10;i++)
46     {
47         if(low>0&&c[a+(b-low)][low]=='X'&&(a+(b-low))<=10)
48             low--;
49         if(hign<=10&&c[a-(hign-b)][hign]=='X'&&(a-(hign-b))>0)
50             hign++;
51     }
52     if(hign-low>5)
53         return true;
54     return false;
55 }
56 
57 int main()
58 {
59     for(int i=1;i<=10;i++)
60         scanf("%s",c[i]+1);
61     for(int i=1;i<=10;i++)
62         for(int j=1;j<=10;j++)
63             if(c[i][j]=='.')
64             {
65                 flag=check(i,j);
66                 if(flag)
67                 {
68                     printf("YES\n");
69                     return 0;
70                 }
71             }
72     printf("NO\n");
73     
74     return 0;
75 }

 

posted @ 2017-08-01 16:50  西北会法语  阅读(135)  评论(0编辑  收藏  举报