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

题意:

多组输入,五子棋的规则。给一个10*10的棋盘,棋盘内有两种棋子“X”和“O”,现在要再加入一个棋子“X”,使得棋子“X”可以按照五子棋的规则连成五个或五个以上。如果加入一个可以连成的话输出“YES”,不能的话输出“NO”。

题解:向8个方向模拟,判断是否可行。(分为4个主要方向)

AC代码:

#include<stdio.h>  

#include<string.h>  

char map[10][10];

int dis[4][4] = { { 0,1,0,-1 },{ 1,0,-1,0 },{ 1,1,-1,-1 },{ -1,1,1,-1 } };

int win(int x, int y)              

{
int xl = x, yl = y, n = 0, m = 0;
while (n + 1<5)             
{
m = 0;
xl = x;
yl = y;
while (map[xl][yl] == 'X')   
{
m++;               
xl = xl + dis[n][0];    
yl = yl + dis[n][1];
if (m == 5)
return 1;
if (xl<0 || yl<0 || xl >= 10 || yl >= 10)//过界,停止  
break;
}                   
m = m - 1;             
xl = x;
xl = y;
while (map[xl][yl] == 'X')
{
m++;
xl = xl + dis[n][2];
yl = yl + dis[n][3];
if (m == 5)
return 1;
if (xl<0 || yl<0 || xl >= 10 || yl >= 10)//过界,停止
break;
}
n++;                    
}
return 0;

}

int main()

{
while (~scanf("%s", map[0]))
{
for (int i = 1; i<10; i++)
scanf("%s", map[i]);
int flag = 0;
for (int i = 0; i<10; i++)
{
for (int j = 0; j<10; j++)
{
if (map[i][j] == '.')
{
map[i][j] = 'X';          
          
if (win(i, j))
{
flag = 1;
break;
}
map[i][j] = '.';      
}
}
if (flag)
break;
}
if (flag)
printf("YES\n");
else printf("NO\n");
}
return 0;

}

FIve in a row的更多相关文章

  1. 浅析MySQL基于ROW格式的二进制日志

    上文分析的二进制日志实际上是基于STATEMENT格式的,下面我们来看看基于ROW格式的二进制日志,毕竟,两者对应的binlog事件类型也不一样,同时,很多童鞋反映基于ROW格式的二进制日志无法查到原 ...

  2. java.lang.IllegalStateException:Couldn't read row 0, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.

    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xxx...}: java.lang.IllegalSta ...

  3. ResultSet can not re-read row data for column 1.

    error:ResultSet can not re-read row data for column 1. 将数据类型改为varchar(max)后,查询数据错误 改正:将jdbc驱动改为jtds驱 ...

  4. 解决一则enq: TX – row lock contention的性能故障

    上周二早上,收到项目组的一封邮件: 早上联代以下时间点用户有反馈EDI导入"假死",我们跟踪了EDI导入服务,服务是正常在跑,可能是处理的慢所以用户感觉是"假死" ...

  5. CI生成查询记录集result(),row(),row_array().....

    result() 该方法执行成功返回一个对象数组,失败则返回一个空数组. 一般情况下,我们使用下面的方法遍历结果,代码就像这样: $query = $this->db->query(&qu ...

  6. SQL——行值表达式(Row Value Expressions)

    概述 最近接触了一个新概念——行值表达式,也叫做行值构造器.这是一个很强大的SQL功能,通常我们所操作的SQL表达式都只能针对一行中的单一字段进行操作比较,而行值表达式可以针对一行中的多个字段进行操作 ...

  7. MySQL主从复制中断,报“Error on master: message (format)='Cannot delete or update a parent row: a foreign key constraint fails' error code=1217” 错误

    前几天,发现从库挂了,具体报错信息如下: 分析思路 1. 因为我采用的是选择性复制,只针对以下几个库进行复制: card,upay,deal,monitor,collect.所以,不太可能出现对于sa ...

  8. WPF DataGrid 鼠标双击选中的DataGridRow及Row数据

    设置DataGrid的MouseDoubleClick事件 代码 //DataGrid鼠标双击事件 Private void dataGrid_MouseDoubleClick(object send ...

  9. ORACLE等待事件:enq: TX - row lock contention

    enq: TX - row lock contention等待事件,这个是数据库里面一个比较常见的等待事件.enq是enqueue的缩写,它是一种保护共享资源的锁定机制,一个排队机制,先进先出(FIF ...

  10. ORACLE AWR结合ASH诊断分析enq: TX - row lock contention

    公司用户反馈一系统在14:00~15:00(2016-08-16)这个时间段反应比较慢,于是生成了这个时间段的AWR报告, 如上所示,通过Elapsed Time和DB Time对比分析,可以看出在这 ...

随机推荐

  1. 小程序---电影商城---第三方组件 vant(vant weapp)

    小程序版本主页 https://youzan.github.io/vant-weapp/#/intro (1)创建项目描述文件 package.json ---鼠标右击 miniprogram  目录 ...

  2. Unity 横版2D移动跳跃问题——关于一段跳与二段跳

    1.初始条件: 1.角色只绑定一个碰撞体,移动时施加力或给予速度,用跳跃次数JumpTimes或者bool值OnGround判断是否在地面. 2.只用一个tilemap搭建2D场景,因此所有tilem ...

  3. java中线程同步的几种方法

    1.使用synchronized关键字 由于java的每个对象都有一个内置锁,当用此关键字修饰方法时, 内置锁会保护整个方法.在调用该方法前,需要获得内置锁,否则就处于阻塞状态. 注: synchro ...

  4. 【Linux系列】Centos 7安装以及网络配置(一)

    目的 本文主要介绍以下两点: 一. 如何在Oracle VM VirtualBox安装centos(已有VirtualBox) 二. 如何在内网里实现虚拟机访问外网.物理主机以及物理主机访问虚拟机 一 ...

  5. ios遇到的坑

    总结体会:很多ios兼容性问题都是由于body设置了height:100% ios中input输入不了 在ios中margin属性不起作用 设置html body的高度为百分比时,margin-bot ...

  6. ES6,import时如何正确使用花括号'{ }'

    在 ES6 之前,社区制定了一些模块加载方案,最主要的有 CommonJS 和 AMD 两种.前者用于服务器,后者用于浏览器.ES6 在语言标准的层面上,实现了模块功能,而且实现得相当简单,完全可以取 ...

  7. hdu 3549 Flow Problem (Dinic)

    Flow ProblemTime Limit: 5000/5000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total ...

  8. (三十五)golang--面向对象之多态

    多态:变量具有多种形态,可以用统一的接口来调用不同的实现. 接口体现多态特征: (1)多态参数:之前所讲的Usb接口案例,既可以接受手机变量,也可以接受相机变量,就体现了usb接口的多态: (2)多台 ...

  9. 解放双手,在PC端进行Android真机调试

    scrcpy简介(拼写是scrcpy,非Python爬虫框架Scrapy) 简单地来说,scrcpy就是通过adb调试的方式来将手机屏幕投到电脑上,并可以通过电脑控制您的Android设备.它可以通过 ...

  10. vim python extension

    1. 检查vim 版本,需高于7.3. 2. Install extension manager : Vundle git clone https://github.com/gmarik/Vundle ...