CodeForces - 825B

Alice and Bob play5-in-a-row game. They have a playing field of size 10 × 10. In turns theyput either crosses or noughts, one at a time. Alice puts crosses and Bob putsnoughts.

In current matchthey have made some turns and now it's Alice's turn. She wonders if she can putcross in such empty cell that she wins immediately.

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

Input

You are givenmatrix 10 × 10 (10 lines of 10 characters each) withcapital Latin letters 'X' being a cross, letters 'O' beinga nought and '.' being an empty cell. The number of 'X' cellsis equal to the number of 'O' cells and there is at least one of eachtype. There is at least one empty cell.

It is guaranteedthat in the current arrangement nobody has still won.

Output

Print 'YES' ifit'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的一方再下一个棋子看看能不能赢,五子棋就是看看,横着,竖着或斜着能不能有连续的五个棋子,可能是小编能力浅薄,没看出要用啥算法,所以呢就直接写啦

思路:把每一个能放棋子的点都判断一下看看能不能赢,若能赢就输出YES,若不能就输出NO;

代码:

#include<stdio.h>
#include<string.h>
char str[15][15];
int check(int y,int x)
{
	int num=0,i,f1=1,f2=1,x1,x2;
	for(i=1;;i++)
	{
		x1=x+i;
		x2=x-i;
		if(f1)
		{
			if(x1>=0&&x1<10&&str[y][x1]=='X')
				num++;
			else f1=0;
		}
		if(f2)
		{
			if(x2>=0&&x2<10&&str[y][x2]=='X')
				num++;
			else f2=0;
		}
		if(!f1&&!f2)
			break;
	}
	if(num>=4) return 1;
	
	num=0;f1=1;f2=1;
	int y1,y2;
	for(i=1;;i++)
	{
		y1=y+i;
		y2=y-i;
		if(f1)
		{
			if(y1>=0&&y1<10&&str[y1][x]=='X')
				num++;
			else f1=0;
		}
		if(f2)
		{
			if(y2>=0&&y2<10&&str[y2][x]=='X')
				num++;
			else f2=0;
		}
		if(!f1&&!f2)
			break;
	}
	if(num>=4) return 1;
	
	num=0;f1=1;f2=1;
	for(i=1;;i++)
	{
		x1=x+i;
		y1=y+i;
		x2=x-i;
		y2=y-i;
		if(f1)
			if(x1>=0&&x1<10&&y1>=0&&y1<10&&str[y1][x1]=='X')
					num++;
			else f1=0;
		if(f2)
			if(x2>=0&&x2<10&&y2>=0&&y2<10&&str[y2][x2]=='X')
					num++;
			else f2=0;
		if(!f1&&!f2)
			break;
	}
	if(num>=4) return 1;
	
	num=0;f1=1;f2=1;
	for(i=1;;i++)
	{
		x1=x+i;
		y1=y-i;
		x2=x-i;
		y2=y+i;
		if(f1)
			if(x1>=0&&x1<10&&y1>=0&&y1<10&&str[y1][x1]=='X')
					num++;
			else f1=0;
		if(f2)
			if(x2>=0&&x2<10&&y2>=0&&y2<10&&str[y2][x2]=='X')
					num++;
			else f2=0;
		if(!f1&&!f2)
			break;
	}
	if(num>=4) return 1;
	
	return 0;
}
int main()
{
	int i,j,k,t,n;
	while(~scanf("%s",str[0]))
	{
		for(i=1;i<10;i++)
			scanf("%s",str[i]);
		int f=0;
		for(i=0;i<10;i++)
		{
			for(j=0;j<10;j++)
			{
				if(str[i][j]=='.')
				{
					if(check(i,j))
					{
						f=1;
						break;
					}
				}
			}
			if(f) break;
		}
		if(f) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
 } 
望博友提些建议,谢谢!

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值