题目链接: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. loadrunner12.5-vugen回放脚本提示:URL=“http://www.testclass.net/js/scripts.js”的常规连接当前无套接字 (16 不足) 可用,是什么意思呢?怎么理解呢?

    会发生这个报错,是因为每个浏览器都有一个限制,检查哪个浏览器客户正在模拟, 通常只允许16个并发连接. 如果超过此超过接数,将显示该消息,通知您没有可用的连接. 而max connection的默认值 ...

  2. 剑指offer面试题3二维数组中的查找

    题目: 在一个二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序.请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数. 需要与面试官确认的是,这 ...

  3. Bootstrap验证

    <div class="modal fade" id="myModal" tabindex="-1" role="dialo ...

  4. js父子窗口传值以及当前页面在js前台如何获得url参数

    1.首先是父页面用window.open打开窗口 <%@ Page Language="C#" AutoEventWireup="true" CodeBe ...

  5. phoenix错误

    spark集群与phoenix进行数据请求时报错: 2018-06-15 17:13:30,158 INFO - Starting task 15.3 in stage 116.0 (TID 6832 ...

  6. 2018.07.03 POJ 2653 Pick-up sticks(简单计算几何)

    Pick-up sticks Time Limit: 3000MS Memory Limit: 65536K Description Stan has n sticks of various leng ...

  7. 2018.09.16 spoj104Highways (矩阵树定理)

    传送门 第一次写矩阵树定理. 就是度数矩阵减去邻接矩阵之后得到的基尔霍夫矩阵的余子式的行列式值. 这个可以用高斯消元O(n3)" role="presentation" ...

  8. arduino一些内容

    arduino 套件使用说明书V1.0.pdf, 步进电机 DHT11 传感器另外一脚要接A0 /* Web client This sketch connects to a website (htt ...

  9. 转@RequestParam,@PathParam,@PathVariable等注解区别

    转自:http://blog.csdn.net/u011410529/article/details/66974974 @RequestParam 和 @PathVariable 注解是用于从requ ...

  10. Shell 基本语法

    一. Linux基本命令 1.1.  cp命令 该命令的功能是将给出的文件或目录拷贝到另一文件或目录中,功能十分强大. 语法: cp [选项] 源文件或目录 目标文件或目录 1.2. mv命令 用户可 ...