Educational Codeforces Round 25 B. Five-In-a-Row
题目链接:http://codeforces.com/contest/825/problem/B
B. Five-In-a-Row
1 second
256 megabytes
standard input
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'.
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的更多相关文章
- Educational Codeforces Round 25 E. Minimal Labels&&hdu1258
这两道题都需要用到拓扑排序,所以先介绍一下什么叫做拓扑排序. 这里说一下我是怎么理解的,拓扑排序实在DAG中进行的,根据图中的有向边的方向决定大小关系,具体可以下面的题目中理解其含义 Educatio ...
- Educational Codeforces Round 6 C. Pearls in a Row
Educational Codeforces Round 6 C. Pearls in a Row 题意:一个3e5范围的序列:要你分成最多数量的子序列,其中子序列必须是只有两个数相同, 其余的数只能 ...
- 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 ...
- Educational Codeforces Round 25 A,B,C,D
A:链接:http://codeforces.com/contest/825/problem/A 解题思路: 一开始以为是个进制转换后面发现是我想多了,就是统计有多少个1然后碰到0输出就行,没看清题意 ...
- 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 ...
- Educational Codeforces Round 25
A 题意:给你一个01的字符串,0是个分界点,0把这个字符串分成(0的个数+1)个部分,分别求出这几部分1的个数.例如110011101 输出2031,100输出100,1001输出101 代码: # ...
- 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 ...
- Educational Codeforces Round 25 D - Suitable Replacement(贪心)
题目大意:给你字符串s,和t,字符串s中的'?'可以用字符串t中的字符代替,要求使得最后得到的字符串s(可以将s中的字符位置两两交换,任意位置任意次数)中含有的子串t最多. 解题思路: 因为知道s中的 ...
- 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 ...
随机推荐
- 论坛遇到附件上传失败问题总结(discuz)
(1)bbs/source/class/class_upload.php 50行左右,注释$attach['target'] $attach['target'] = DISCUZ_ROOT.'./da ...
- Jmeter If Controller中设置多个条件用“与”进行连接
"${noteID}"!="NOT FOUND" && "${securitiesId}"!="0P00011FQ ...
- 如何删除win8自带输入法
如何删除 win8 自带输入法 win8 自带的那个中文输入法太坑了,想删又删不了.试了半个小时才试出一个方法.方法如下: 第一步:在更改语言道选项下面点击[添加语言] [控制面板] -> [时 ...
- 学习GIT 版本控制的好去处 另GDB资料
廖雪峰的官方网站 http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000 作者不仅仅是做技 ...
- bootstrap-datepicker 与bootstrapValidator同时使用时,选择日期后,无法正常触发校验
bootstrap-datepicker 与bootstrapValidator同时使用时,选择日期后,无法正常触发校验 (解决办法) http://blog.csdn.net/biedazhangs ...
- Linux的简单介绍和开发基本运维时候用到的命令
先简单介绍下Linux文件夹目录 1./ linux下的根目录 实际上等同于window的我的电脑点进去 2./etc /usr 一个是系统配置文件存放的地方,一个是系统资源(应用程序)放的地方这俩文 ...
- 2018上IEC计算机高级语言(C)作业 第0次作业
最理想的师生关系是健身教练和学员的关系,在这种师生关系中你期望获得来自老师的哪些帮助? 最理想的的师生关系是健身教练和学员的关系,其实我个人感觉不太认同,我觉得老师和学生之间更多的是一种共生关系,像植 ...
- springMVC学习(注解实现依赖注入)
原文:http://blog.csdn.net/mockingbirds/article/details/45399691 上一篇博客,学习了spring的依赖注入,即利用spring容器来为类中的属 ...
- (转)code first基础
转自:http://tech.it168.com/a2011/0719/1220/000001220362_all.shtml [IT168 技术]随着.NET 4.0时代的到来,开发者越来越关注如何 ...
- (转载)从Java角度理解Angular之入门篇:npm, yarn, Angular CLI
本系列从Java程序员的角度,带大家理解前端Angular框架. 本文是入门篇.笔者认为亲自动手写代码做实验,是最有效最扎实的学习途径,而搭建开发环境是学习一门新技术最需要先学会的技能,是入门的前提. ...