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 ...
随机推荐
- linux下安装php php-fpm(转载)
centos安装php php-fpm 1.下载php源码包http://www.php.net/downloads.php2 .安装phptar -xvf php-5.5.13.tar.bz2cd ...
- gruop by报错this is incompatible with sql_mode=only_full_group_by
set @@GLOBAL.sql_mode=''; set sql_mode ='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_ ...
- bat 调用exe
@set errorlevel=>nul :reInput @echo 请输入批次号: @set/p 批次号= >nul @set 批次号|findstr "\\<%sea ...
- 使用WebUploader客户端批量上传图片,后台使用springMVC接收实例
使用WebUploader客户端批量上传图片,后台使用springMVC接收实例 我是搞Java后台的,因为最近主管让用webUploader写客户端,但是在网上找了很多,能够复制就能用的并没有几个, ...
- 对于Serializable id类型的数据的测试
今天编写了一个这样的例子,然后进行了Junit测试,但是发现类型总是不匹配,最后测出如下 public <T> void deleteEntry(Class<T> t, Ser ...
- HDU 2058 The sum problem (数学+暴力)
题意:给定一个N和M,N表示从1到N的连续序列,让你求在1到N这个序列中连续子序列的和为M的子序列区间. 析:很明显最直接的方法就是暴力,可是不幸的是,由于N,M太大了,肯定会TLE的.所以我们就想能 ...
- webuploader 文件上传插件 IE8/9 文件选择不上传
IE8/9下文件上传是采用flash模式,一直发送http://xxx.xxx.xx.xx:8888/crossdomain.xml请求,状态码为404,原因是上传文件的服务器未配置crossdoma ...
- webuploader php上传视频
webuploader 上传大视频文件 在网上找了一个,自己重新组合了下,两个主要的文件,再加上官方下载的文件.其中有几个重要的点. 1.上传存放视频目录为了测试 直接777 2.fileupload ...
- (二)spring-mvc-showcase 和 swagger-springmvc 的恩恩怨怨
1. 搜索 spring showcase 就可以找到这篇 http://spring.io/blog/2010/07/22/spring-mvc-3-showcase 就是教你如何使用spring ...
- volatile 类型修饰符
volatile 类型修饰符 1.解释 就像大家更熟悉的const一样,volatile是一个类型修饰符(type specifier).它是被设计用来修饰被不同线程访问和修改的变量.如果不加入vol ...