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.
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.
Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'.
XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... ..........
YES
XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... ..........
NO
idea:枚举每一个'.'位置,把这个'.'变成'X'然后从左到右 从上到下 从左上到右下 从右上到左下判断是否有5个棋子以上连通即可。可能代码有点长,因为我傻逼。
//china no.1
#include <vector>
#include <iostream>
#include <string>
#include <map>
#include <stack>
#include <cstring>
#include <queue>
#include <list>
#include <stdio.h>
#include <set>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <cctype>
#include <sstream>
#include <functional>
#include <stdlib.h>
#include <time.h>
using namespace std;
#define pi acos(-1)
#define endl '\n'
#define srand() srand(time(0));
#define me(x) memset(x,0,sizeof(x));
#define foreach(it,a) for(__typeof((a).begin()) it=(a).begin();it!=(a).end();it++)
#define close() ios::sync_with_stdio(0); cin.tie(0);
typedef long long LL;
const int INF=0x3f3f3f3f;
const LL LINF=0x3f3f3f3f3f3f3f3fLL;
//const int dx[]={-1,0,1,0,-1,-1,1,1};
//const int dy[]={0,1,0,-1,1,-1,1,-1};
const int maxn=1e3+5;
const int maxx=1e5+100;
const double EPS=1e-7;
const int MOD=10000007;
#define mod(x) ((x)%MOD);
template<class T>inline T min(T a,T b,T c) { return min(min(a,b),c);}
template<class T>inline T max(T a,T b,T c) { return max(max(a,b),c);}
template<class T>inline T min(T a,T b,T c,T d) { return min(min(a,b),min(c,d));}
template<class T>inline T max(T a,T b,T c,T d) { return max(max(a,b),max(c,d));}
#define FOR(x,n,i) for(int i=x;i<=n;i++)
#define FOr(x,n,i) for(int i=x;i<n;i++)
#define W while
inline int Scan()
{
int res=0,ch,flag=0;
if((ch=getchar())=='-')flag=1;
else if(ch>='0' && ch<='9')res=ch-'0';
while((ch=getchar())>='0'&&ch<='9')res=res*10+ch-'0';
return flag ? -res : res;
}
char mapp[25][25];
int check(int x,int y)
{
if(x>=1&&x<=10&&y>=1&&y<=10&&mapp[x][y]=='X')
return 1;
return 0;
}
int val=0;
int main()
{
FOR(1,10,i)
cin>>mapp[i]+1;
FOR(1,10,i)
FOR(1,10,j)
{
if(mapp[i][j]=='.')
{
int flag=0;
mapp[i][j]='X';
int tx=1,ty=j;
FOR(1,10,k)
{
FOR(1,10,b)
{
tx=k;tx=b;
if(check(tx,ty))
{
FOR(0,4,z)
{
if(!check(tx+z,ty))
flag=1;
}
}
else continue;
if(flag==1)
{
flag=0;
continue;
}
else val=1;
}
}
tx=i,ty=1;
FOR(1,10,k)
{
FOR(1,10,b)
{
ty=k;tx=b;
if(check(tx,ty))
{
FOR(0,4,z)
{
if(!check(tx,ty+z))
flag=1;
}
}
else continue;
if(flag==1)
{
flag=0;
continue;
}
else val=1;
}
}
tx=1,ty=1;
FOR(1,10,k)
{
FOR(1,10,b)
{
ty=k;tx=b;
if(check(tx,ty))
{
FOR(0,4,z)
{
if(!check(tx-z,ty+z))
flag=1;
}
}
else continue;
if(flag==1)
{
flag=0;
continue;
}
else val=1;
}
}
tx=10,ty=10;
FOR(1,10,k)
{
FOR(1,10,b)
{
ty=11-k;tx=11-b;
if(check(tx,ty))
{
FOR(0,4,z)
{
if(!check(tx-z,ty-z))
flag=1;
}
}
else continue;
if(flag==1)
{
flag=0;
continue;
}
else val=1;
}
}
mapp[i][j]='.';
}
}
if(val)
puts("YES");
else puts("NO");
}