题目链接:http://codeforces.com/contest/825/problem/B

B. Five-In-a-Row

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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
Input
XX.XX.....
.....OOOO.
..........
..........
..........
..........
..........
..........
..........
..........

Output

YES

Input

XXOXX.....
OO.O......
..........
..........
..........
..........
..........
..........
..........
..........

Output

NO

题意:

找到一个'.',将它改成'X'后,能否出现5子连线.

题解:

因为棋盘是10*10,所以直接暴力深搜即可,标记做好,然后判断是否符合题意.

代码:

#include<cstring>
#include<cstdio>
#include<iostream>
using namespace std;
#define maxn 15
char str[maxn][maxn];
bool vis[maxn][maxn],ans;
int dirx[]={,,-,,,-,,-,},diry[]={-,,,,,-,-,,};
bool valid(int x,int y)
{
if(x>=&&x<&&y>=&&y<) return true;
else return false;
}
void dfs(int x,int y,int lx,int ly,int cnt,bool flag)
{
vis[x][y]=true;
if(cnt>=) {ans=true; return ;}
bool FLAG=false;
if(str[x][y]=='.') flag=true;
if(lx==-&&ly==-) FLAG=true;
for(int i=;i<;i++)
{
int nx=dirx[i]+x,ny=diry[i]+y;
if(FLAG) {lx=dirx[i],ly=diry[i];}
if(valid(nx,ny)&&!vis[nx][ny]&&str[nx][ny]=='X'&&dirx[i]==lx&&diry[i]==ly)
dfs(nx,ny,dirx[i],diry[i],cnt+,flag);
else if(valid(nx,ny)&&!vis[nx][ny]&&str[nx][ny]=='.'&&!flag&&dirx[i]==lx&&diry[i]==ly)
dfs(nx,ny,dirx[i],diry[i],cnt+,);
}
}
int main()
{
for(int i=;i<;i++) scanf("%s",str[i]);
for(int i=;i<;i++)
for(int j=;j<;j++)
{
memset(vis,false,sizeof(vis));
if(str[i][j]=='X'||str[i][j]=='.') dfs(i,j,-,-,,);
}
if(ans) puts("YES");
else puts("NO");
return ;
}

Educational Codeforces Round 25 B. Five-In-a-Row的更多相关文章

  1. Educational Codeforces Round 25 E. Minimal Labels&&hdu1258

    这两道题都需要用到拓扑排序,所以先介绍一下什么叫做拓扑排序. 这里说一下我是怎么理解的,拓扑排序实在DAG中进行的,根据图中的有向边的方向决定大小关系,具体可以下面的题目中理解其含义 Educatio ...

  2. Educational Codeforces Round 6 C. Pearls in a Row

    Educational Codeforces Round 6 C. Pearls in a Row 题意:一个3e5范围的序列:要你分成最多数量的子序列,其中子序列必须是只有两个数相同, 其余的数只能 ...

  3. Educational Codeforces Round 25 Five-In-a-Row(DFS)

    题目网址:http://codeforces.com/contest/825/problem/B 题目:   Alice and Bob play 5-in-a-row game. They have ...

  4. Educational Codeforces Round 25 A,B,C,D

    A:链接:http://codeforces.com/contest/825/problem/A 解题思路: 一开始以为是个进制转换后面发现是我想多了,就是统计有多少个1然后碰到0输出就行,没看清题意 ...

  5. Educational Codeforces Round 25 C. Multi-judge Solving

    题目链接:http://codeforces.com/contest/825/problem/C C. Multi-judge Solving time limit per test 1 second ...

  6. Educational Codeforces Round 25

    A 题意:给你一个01的字符串,0是个分界点,0把这个字符串分成(0的个数+1)个部分,分别求出这几部分1的个数.例如110011101 输出2031,100输出100,1001输出101 代码: # ...

  7. Educational Codeforces Round 25 E. Minimal Labels 拓扑排序+逆向建图

    E. Minimal Labels time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  8. Educational Codeforces Round 25 D - Suitable Replacement(贪心)

    题目大意:给你字符串s,和t,字符串s中的'?'可以用字符串t中的字符代替,要求使得最后得到的字符串s(可以将s中的字符位置两两交换,任意位置任意次数)中含有的子串t最多. 解题思路: 因为知道s中的 ...

  9. Educational Codeforces Round 6 C. Pearls in a Row set

    C. Pearls in a Row There are n pearls in a row. Let's enumerate them with integers from 1 to n from ...

随机推荐

  1. 深入php内核,从底层c语言剖析php实现原理

    深入php内核,从底层c语言剖析php实现原理 非常好的电子书:http://www.cunmou.com/phpbook/preface.md   这是它的目录: PHP的生命周期 让我们从SAPI ...

  2. linux下iptables防火墙设置

    各位linux的爱好者或者工作跟linux相关的程序员,我们在工作中经常遇到应用服务器端口已经启动, 在网络正常的情况下,访问不到应用程序,这个跟防火墙设置有关 操作步骤 1.检查有没有启动防火墙 s ...

  3. laravel增删改查(查询构建器)

    1.增 $data = [ 'username' => 'xiaohong', 'nickname' => '小红红', 'email' => '12356788@qq.com', ...

  4. mysql添加注释

    -- 查看字段类型-- show columns from campaign_distribute --给表添加注释 -- alter table campaign_distribute commen ...

  5. 8.14 右键自定义菜单 更加iframe 内容高度调整 iframe高度 js定时

    <div class="main_contain" id="z_div" style="position: relative;"> ...

  6. centos6.5 设置ssh无密码登录

    :关闭防火墙 vim /etc/selinux/config 把SELINUX=enforcing修改为SELINUX=disabled   A机器root连接B机器root用户 (root用户登录) ...

  7. 【Win】使用ScreenToGif制作gif动态图片

    ScreenToGif 经常要写各类教程,有时候需要制作一些演示动画,GIF动画图片是个不错的选择,ScreenToGif是一款GIF录屏软件,下载地址可自行百度. 运行环境 操作系统:windows ...

  8. BaseAdapter

    作者通过Java代码来实现布局,而我习惯通过.xml文件来实现,所以我对程序做了如下修改 MainActivity.java public class MainActivity extends Act ...

  9. UVa 11491 Erasing and Winning (贪心,单调队列或暴力)

    题意:给一个数字(开头非0),拿掉其中的d个数字,使剩下的数字最大(前后顺序不能变). 析:拿掉d个数字,还剩下n-d个数字.相当于从n个数字中按先后顺序选出n-d个数字使组成的数字最大,当然采用窗口 ...

  10. Linux下Git安装及配置

    转载自:https://blog.csdn.net/u013256816/article/details/54743470:加了一些自己的注释. yum安装 这里采用的是CentOS系统,如果采用yu ...