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 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.
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.
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.
..........
..........
..........
..........
..........
..........
..........
..........
YES
XXOXX.....
OO.O......
..........
..........
..........
..........
..........
..........
..........
..........
NO 思路:因为只有10*10,所以直接用了暴力搜索。
代码:
#include <cstdio>
#include <vector>
using namespace std;
struct node{
int x,y;
}dir[]={{,},{,-},{,},{-,},{-,-},{-,},{,},{,-}};
int row[];
int col[];
int ok=;
char graph[][];
vector<node>v;
bool check(int x,int y){
if(x< || x>=) return false;
if(y< || y>=) return false;
if(graph[x][y]!='X') return false;
return true;
}
void dfs(int x,int y,int d,int num){
if(!check(x, y)) return ;
if(num==){
ok=;
return ;
}
int xt=x+dir[d].x;
int yt=y+dir[d].y;
dfs(xt,yt,d,num+); }
int main(){
for (int i=; i<; i++) {
gets(graph[i]);
for(int j=;j<;j++){
if(graph[i][j]=='X'){
node t;
t.x=i;
t.y=j;
v.push_back(t);
}
}
}
for (int i=; i< && !ok; i++) {
for (int j=; j< && !ok; j++) {
if(graph[i][j]!='.') continue;
graph[i][j]='X';
for(int i=;i<v.size() && !ok;i++){
for(int d=;d<;d++) dfs(v[i].x,v[i].y,d,);
}
graph[i][j]='.';
}
}
if(ok) printf("YES\n");
else printf("NO\n");
return ;
}
Educational Codeforces Round 25 Five-In-a-Row(DFS)的更多相关文章
- Educational Codeforces Round 25 E. Minimal Labels&&hdu1258
这两道题都需要用到拓扑排序,所以先介绍一下什么叫做拓扑排序. 这里说一下我是怎么理解的,拓扑排序实在DAG中进行的,根据图中的有向边的方向决定大小关系,具体可以下面的题目中理解其含义 Educatio ...
- 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 B. Five-In-a-Row
题目链接:http://codeforces.com/contest/825/problem/B B. Five-In-a-Row time limit per test 1 second memor ...
- 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 E. New Year Tree dfs+线段树
题目链接:http://codeforces.com/contest/620/problem/E E. New Year Tree time limit per test 3 seconds memo ...
- Educational Codeforces Round 6 C. Pearls in a Row
Educational Codeforces Round 6 C. Pearls in a Row 题意:一个3e5范围的序列:要你分成最多数量的子序列,其中子序列必须是只有两个数相同, 其余的数只能 ...
随机推荐
- 测试工具——JMeter
本学期新学的课程,软件测试,上机的实验用到了C++Test,QTP,还有JMeter.今天针对JMeter做一次总结,方便以后用到,知道步骤会更加方便. 首先,对Jmeter进行一个大致的了解,包括对 ...
- 读阿里巴巴Java开发手册v1.2.0之编程规约有感【架构篇】
不为过去蹉跎,改变当下. 为什么开篇就送这么一句话给大家,我相信很多处于1-3年码龄的哥们儿们,在平时的编码历程中编码的个性可能是多彩的,每个人都有每个人特定的风格,但是我们现在这么随意写,以后这么 ...
- 基于Express+Socket.io+MongoDB的即时聊天系统的设计与实现
记得从高中上课时经常偷偷的和同学们使用qq进行聊天,那时候经常需要进行下载qq,但是当时又没有那么多的流量进行下载,这就是一个很尴尬的事情了,当时就多想要有一个可以进行线上聊天的网站呀,不用每次痛苦的 ...
- Python进制转换(二进制、十进制和十六进制)
#!/usr/bin/env python # -*- coding: utf-8 -*- # 2/10/16 base trans. wrote by srcdog on 20th, April, ...
- solr学习笔记section2-solr单机(节点)简单的core操作
在上一节中我们已经成功部署和运行了一个solr应用,那么我们就可以通过这个正在运行的solr来创建一些文档,并进行搜索. 首先介绍一下core这个概念,core在solr中类似与关系型数据库中一张表的 ...
- 一道C语言安全编码题目
1.前言 最近在网上看到一道C语言题目,用C语言实现一个函数,给定一个int类型的整数,函数输出逆序的整数,例如输入123,则输出字符串"321",,输入-123,则输出字符串&q ...
- 14.Java中的Future模式
jdk1.7.0_79 本文实际上是对上文<13.ThreadPoolExecutor线程池之submit方法>的一个延续或者一个补充.在上文中提到的submit方法里出现了Future ...
- oracle表空间自增长
方式一:通过修改oracle database control 修改 第一步,点击开始--所有程序--Oracle - OraDb11g_home1--Database Control 第二步,通过g ...
- C#继承的执行顺序
自己对多态中构造函数.函数重载执行顺序和过程一直有些不理解,经过测试,对其中的运行顺序有了一定的了解,希望对初学者有些帮助. eg1: public class A { public A() { Co ...
- 关于MATLAB处理大数据坐标文件2017529
今天我们离成功又近了一步,因为又失败了两次 第一次使用了所有特征,理由:前天的特征使用的是取单个特征测试超过85分的特征,结果出现过拟合现象. 本次使用所有特征是为了和昨天的结果作比较. 结果稍好:比 ...