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 ...
随机推荐
- Mininet
在Coursera SDN开放课程中,编程作业要用Mininet来完成.这里对Mininet做一个简单的介绍. 什么是Mininet Mininet是由一些虚拟的终端节点(end-hosts).交换机 ...
- linux 基本工具相关
首先是linux下安装ssh服务(root) 由于是使用debian版本 与其他稍有差别 安装服务 apt-get install ssh 查看服务是否开启 service ssh status 开启 ...
- for() 和$.each()的用法区别
一.对于数组 var arr=['姚明','易建联','张继科']; $.each(arr,function(index,value){ document.write(index+"=&qu ...
- 2018.10.19 NOIP训练 yk赚钱记(01分数规划)
传送门 其实是一个裸的最优比率生成树. 注意精度的控制就行了. 代码
- 2018.07.23 洛谷P4097 [HEOI2013]Segment(李超线段树)
传送门 给出一个二维平面,给出若干根线段,求出x" role="presentation" style="position: relative;"&g ...
- Java基础知识学习笔记(一)
理解面向对象: Java纯粹的面向对象的程序设计语言,主要表现为Java完全支持面向对象的三个基本特征:继承.封装.多态. Java程序的最小单位是类,类代表客观世界中具有某种特征的一类事物,这些类可 ...
- MFC 的SetWindowPos 用法
转自于:http://hi.baidu.com/max_new/blog/item/e2bbe607b1f127c57b8947c0.html 许多软件,特别是占桌面面积不是很大的软件,通常都提供了一 ...
- POJ3258 River Hopscotch 2017-05-11 17:58 36人阅读 评论(0) 收藏
River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 13598 Accepted: 5791 ...
- Example11(June 9,2015)
%--------------sort------------------------------- >> A=[ ; ; ] A = >> B=sort(A,)%A(:,)& ...
- ios开发 ad hoc怎么用
简单的说就是这样 ad hoc 方式是苹果用来给未上线的app做测试用的,首先你要在苹果开发平台上申请一个ad hoc的证书,再在profile中生成一个ad hoc 的profile文件(只需要在生 ...