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 ...
随机推荐
- Windows Server 2008 IIS 并发请求设置
更新服务器的时候,突然发现部分机器出现了错误,大致描述如下 HTTP Error 503.2 - Service Unavailable 正在超过 serverRuntime@appConcurren ...
- scrapy--多爬虫
大家好,我胡汉三又回来了!!!开心QAQ 由于最近一直在忙工作的事,之前学的一些爬虫知识忘得差不多了,只能再花多一些时间来回顾,否则根本无法前进.所以在这里也像高中老师那样提醒一下大家,--每天晚上花 ...
- 【TP5.1】HTML标签自动转义,导致CKEditor保存内容无法正常显示!
问题:使用Thinkphp5.1 开发的时候显示CKEditor保存的内容不符合预期. 希望的样子,肯定是不显示<p><b>等标签,而是下面的样子. 因为刚开始使用TP5.1和 ...
- 海康威视面试python后端题
1. 请简述三次握手和四次挥手: 答:首先TCP是传输控制协议,提供可靠的连接服务,采用三次握手确认建立一个连接,在建立TCP连接时,需要客户端和服务器总共发送3个包. 三次握手的目的是连接服务器的指 ...
- Codeforces Round #459 (Div. 2) D. MADMAX DFS+博弈
D. MADMAX time limit per test 1 second memory limit per test 256 megabytes input standard input outp ...
- 3. 与服务器对话:理解 HTTP 协议
0.服务器与本地交换机制 2.详解HTtp服务 (1)与服务器对话的流程 (2)Reque 请求 (3)Response 响应 200 成功 404 没有网页 (4)Get/Post区别 get查询数 ...
- echart搭配时间轴进行展示 (本例展示的是多时间 多地区 多指标条件 )
1:照常先来几张图 看效果 2:首先 看官方文档 我把echart官方的例子给扒下来并整理了得出如下效果 上 案例图和代码 效果图 : 代码: <style type="text/c ...
- bootstrap重新设计按钮样式
1.将btn的样式换成以下的样式 2.思路: (1)将原来的btn样式设置color:#FFF,同时text-shadow设置,这样原来的btn样式就会变淡了,后面再加上新的样式就可以覆盖掉 注意:要 ...
- 关于mac ox node安装报 npm ERR! registry error parsing json
想安装grunt 遇到2个问题 让npm重新设置一下config: npm config set registry http://registry.cnpmjs.org 然后还报 npm ERR! E ...
- NOIP2018 集训(一)
A题 Simple 时间限制:1000ms | 空间限制:256MB 问题描述 对于给定正整数\(n,m\),我们称正整数\(c\)为好的,当且仅当存在非负整数\(x,y\)使得\(n×x+m×y=c ...