Codeforces Round #290 (Div. 2) B. Fox And Two Dots(DFS)
http://codeforces.com/problemset/problem/510/B
#include "cstdio"
#include "cstring"
int r,c;
char map[][];
int vis[][];
int mark;
int dx[]={,-,,},dy[]={,,,-};
int judge(int x,int y)
{
if(x<||x>=r||y<||y>=c)
return ;
return ;
}
void dfs(int x,int y,int perX,int perY)
{
if(!judge(x,y))
return;
vis[x][y]=;
for(int i=;i<;i++)
{
int xx=x+dx[i];
int yy=y+dy[i];
if(map[xx][yy]==map[x][y]&&judge(xx,yy)&&(xx!=perX||yy!=perY))
{
if(vis[xx][yy])
{
mark=;
return;
}
dfs(xx,yy,x,y);
}
}
return;
}
int main()
{
while(scanf("%d%d",&r,&c)!=EOF)
{
memset(vis,,sizeof(vis));
for(int i=;i<r;i++)
scanf("%s",map[i]);
mark=;
int flag=;
for(int i=;i<r;i++)
{
for(int j=;j<c;j++)
{
if(!vis[i][j])
{
dfs(i,j,,);
if(mark)
{
break;
}
}
}
if(mark)
{
break;
}
}
if(mark)
printf("Yes\n");
else
printf("No\n"); }
return ;
}
Codeforces Round #290 (Div. 2) B. Fox And Two Dots(DFS)的更多相关文章
- Codeforces Round #290 (Div. 2) B. Fox And Two Dots dfs
B. Fox And Two Dots 题目连接: http://codeforces.com/contest/510/problem/B Description Fox Ciel is playin ...
- DFS Codeforces Round #290 (Div. 2) B. Fox And Two Dots
题目传送门 /* DFS:每个点四处寻找,判断是否与前面的颜色相同,当走到已走过的表示成一个环 */ #include <cstdio> #include <iostream> ...
- Codeforces Round #228 (Div. 2) C. Fox and Box Accumulation(贪心)
题目:http://codeforces.com/contest/389/problem/C 题意:给n个箱子,给n个箱子所能承受的重量,每个箱子的重量为1: 很简单的贪心,比赛的时候没想出来.... ...
- Codeforces Round #529 (Div. 3) E. Almost Regular Bracket Sequence (思维)
Codeforces Round #529 (Div. 3) 题目传送门 题意: 给你由左右括号组成的字符串,问你有多少处括号翻转过来是合法的序列 思路: 这么考虑: 如果是左括号 1)整个序列左括号 ...
- Codeforces Round #356 (Div. 2) C. Bear and Prime 100(转)
C. Bear and Prime 100 time limit per test 1 second memory limit per test 256 megabytes input standar ...
- 17-比赛2 F - Fox And Two Dots (dfs)
Fox And Two Dots CodeForces - 510B ================================================================= ...
- Codeforces Round #290 (Div. 2) D. Fox And Jumping dp
D. Fox And Jumping 题目连接: http://codeforces.com/contest/510/problem/D Description Fox Ciel is playing ...
- Codeforces Round #290 (Div. 2) C. Fox And Names dfs
C. Fox And Names 题目连接: http://codeforces.com/contest/510/problem/C Description Fox Ciel is going to ...
- Codeforces Round #290 (Div. 2) A. Fox And Snake 水题
A. Fox And Snake 题目连接: http://codeforces.com/contest/510/problem/A Description Fox Ciel starts to le ...
随机推荐
- 传输控制协议(TCP)
传输控制协议(TCP)[来自Unix网络编程(卷一)第2章] 1.TCP是一个面向连接.可靠性的传输协议: 2.TCP含有用于动态估算客户与服务器之间往返时间(RTT)的算法,以便它知道等待一个确认需 ...
- php-5.6.26源代码 - PHP文件汇编成opcode、执行
文件 php-5.6.26/Zend/zend.c ZEND_API int zend_execute_scripts(int type TSRMLS_DC, zval **retval, int f ...
- 【Sklearn系列】使用Sklearn进行数据预处理
这篇文章主要讲解使用Sklearn进行数据预处理,我们使用Kaggle中泰坦尼克号事件的数据作为样本. 读取数据并创建数据表格,查看数据相关信息 import pandas as pd import ...
- Storm: 集群安装和配置
前期准备:3台服务器: 192.168.8.94 192.168.8.95 192.168.8.96 去storm官网下载响应版本的软件包:http://storm.apache.org/downl ...
- Kali Linux 搜狗输入法安装
1.下载 搜狗输入法 for Linux http://pinyin.sogou.com/linux/ //有64位和32位的deb包 我这里下载的是 : sogoupinyin_2.1.0.0086 ...
- 探究SynchronizationContext在.Net异步编程中的地位
原文:探究SynchronizationContext在.Net异步编程中的地位 引言: 多线程编程/异步编程非常复杂,有很多概念和工具需要去学习,贴心的.NET提供Task线程包装类和await/a ...
- WPF图片预览之移动、旋转、缩放
原文:WPF图片预览之移动.旋转.缩放 RT,这个功能比较常见,但凡涉及到图片预览的都跑不了,在说自己的实现方式前,介绍一个好用的控件:Extended.Toolkit中的Zoombox,感兴趣的同学 ...
- Internet接入方式
(转载) 接入网可以大概分成两类:拨号上网(包括ASDL)与专线上网 在接入网中,目前可供选择的接入方式主要有PSTN.ISDN.DDN.LAN.ADSL.VDSL.Cable-Modem.PON和L ...
- Windows Server 2012 R2有哪些存储监控工具
[TechTarget中国原创] 大多数Windows管理员都知道,没有一种单一的方法可以用来监控存储或磁盘错误.虽然市场上有无数的管理工具可供你选择,但由于政策和规程的原因,企业之间的选择不尽相同. ...
- 初学JS——实现基于计时器的小游戏。
这几天一直在看网易云课堂上免费的JS课程,正好今天看到讲了计时器setInterval,第一感觉就是像C#里的TIMER.然后课程里举得例子正好通过计时器改变新生成窗口的位置, 然后就突然有了灵感!可 ...