codeforces#290 B&&510 B Fox And Two Dots (简单dfs)
来源:互联网 发布:阿里云ecs绑定域名 编辑:程序博客网 时间:2024/05/19 00:43
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; char s[56][56]; int vis[56][56]; int n, m; int xx[4] = {0,-1,1,0}; int yy[4] = {1,0,0,-1}; char tt; int mark; int judge(int x, int y) { if(x>=0 && x<n && y>=0 && y<m) return 1; else return 0; } void dfs(int x, int y, int fx, int fy) { if(!judge(x, y)) return ; vis[x][y] = 1; for(int i = 0; i < 4; i++) { int tx = x + xx[i]; int ty = y + yy[i]; if(judge(tx,ty) && s[x][y]==s[tx][ty] && (tx!=fx || ty!=fy)) { if(vis[tx][ty]) { mark = 1; return ; } dfs(tx, ty, x, y); } } return ; } int main() { while(~scanf("%d%d",&n,&m)) { memset(vis,0,sizeof(vis)); for(int i = 0; i < n ; i++) { scanf("%s",s[i]); } mark = 0; for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) { if(!vis[i][j]) { dfs(i,j,-1,-1); if(mark) { printf("Yes\n"); return 0; } } } } printf("No\n"); } }
0 0
- codeforces#290 B&&510 B Fox And Two Dots(简单dfs)
- codeforces#290 B&&510 B Fox And Two Dots (简单dfs)
- codeforces#290 B&&510 B Fox And Two Dots(简单dfs)
- codeforces B. Fox And Two Dots (dfs)
- CodeForces 510 B. Fox And Two Dots(DFS)
- Codeforces 510B Fox And Two Dots DFS
- codeforces-510B-Fox And Two Dots【DFS】
- CodeForces 510B Fox And Two Dots(DFS)
- CodeForces 510B Fox And Two Dots (DFS)
- 【Codeforces】-510B-Fox And Two Dots(dfs)
- DFS CodeForces 510B (Fox And Two Dots)
- CodeForces 510B Fox And Two Dots(深搜DFS)
- 【CodeForces 510B】 Fox And Two Dots (dfs+bfs)
- CodeForces 510B Fox And Two Dots
- 【CodeForces 510B】Fox And Two Dots
- Codeforces 510B. Fox And Two Dots
- codeforces 510b Fox And Two Dots
- B. Fox And Two Dots———简单DFS
- JavaScript DOM
- UIButton实现左文字右图片
- python标准库概览
- django 实现简单的插入视频
- 华为OJ——字符串运用-密码截取
- codeforces#290 B&&510 B Fox And Two Dots (简单dfs)
- js创建对象
- 华为OJ——求最大连续bit数
- Opencv图像识别从零到精通(27)---grabcut
- 正则表达式复习+python使用正则
- 2016.08.12【初中部 NOIP提高组 】模拟赛C题解
- Windows和Linux互相访问远程桌面
- 那些年在前端踩的坑
- MATLAB数据分析与挖掘实战-数据探索-3.1 数据质量分析