DFS Codeforces Round #290 (Div. 2) B. Fox And Two Dots
题目传送门
1 /* 2 DFS:每个点四处寻找,判断是否与前面的颜色相同,当走到已走过的表示成一个环 3 */ 4 #include <cstdio> 5 #include <iostream> 6 #include <cstring> 7 #include <string> 8 #include <map> 9 #include <algorithm> 10 #include <vector> 11 #include <set> 12 #include <cmath> 13 using namespace std; 14 15 const int MAXN = 1e6 + 10; 16 const int INF = 0x3f3f3f3f; 17 int dx[4] = {1, -1, 0, 0}; 18 int dy[4] = {0, 0, 1, -1}; 19 char a[55][55]; 20 int used[55][55]; 21 int n, m; 22 23 bool DFS(int x, int y, int px, int py, char ch) 24 { 25 used[x][y] = 1; 26 for (int i=0; i<=4-1; ++i) 27 { 28 int tx = x + dx[i]; 29 int ty = y + dy[i]; 30 if (tx == px && ty == py) continue; 31 if (tx >= 0 && tx <= n-1 && ty >= 0 && ty <=m-1 && a[tx][ty] == ch) 32 { 33 if (used[tx][ty]) return true; 34 if (DFS (tx, ty, x, y, ch)) return true; 35 } 36 } 37 38 return false; 39 } 40 41 int main(void) 42 { 43 //freopen ("B.in", "r", stdin); 44 45 while (cin >> n >> m) 46 { 47 memset (used, 0, sizeof (used)); 48 for (int i=0; i<=n-1; ++i) 49 { 50 scanf ("%s", &a[i]); 51 } 52 53 bool flag = false; 54 for (int i=0; i<=n-1; ++i) 55 { 56 for (int j=0; j<=m-1; ++j) 57 { 58 if (!used[i][j]) 59 { 60 if (DFS (i, j, -1, -1, a[i][j])) 61 { 62 puts ("Yes"); flag = true; break; 63 } 64 } 65 } 66 if (flag) break; 67 } 68 69 if (!flag) puts ("No"); 70 } 71 72 return 0; 73 }
转载于:https://www.cnblogs.com/Running-Time/p/4366706.html
DFS Codeforces Round #290 (Div. 2) B. Fox And Two Dots相关推荐
- 拓扑排序 Codeforces Round #290 (Div. 2) C. Fox And Names
题目传送门 1 /* 2 给出n个字符串,求是否有一个"字典序"使得n个字符串是从小到大排序 3 拓扑排序 4 详细解释:http://www.2cto.com/kf/201502 ...
- DFS Codeforces Round #299 (Div. 2) B. Tavas and SaDDas
题目传送门 1 /* 2 DFS:按照长度来DFS,最后排序 3 */ 4 #include <cstdio> 5 #include <algorithm> 6 #includ ...
- CodeForces Round #290 Div.2
A. Fox And Snake 代码可能有点挫,但能够快速A掉就够了. 1 #include <cstdio> 2 3 int main() 4 { 5 //freopen(" ...
- dfs Codeforces Round #356 (Div. 2) D
http://codeforces.com/contest/680/problem/D 题目大意:给你一个大小为X的空间(X<=m),在该空间内,我们要尽量的放一个体积为a*a*a的立方体,且每 ...
- Codeforces Round #290 (Div. 2)C
C. Fox And Names 原题 Time Limit 2s Memory Limit 256M Fox Ciel is going to publish a paper on FOCS (Fo ...
- Codeforces Round #628 (Div. 2) F. Ehab‘s Last Theorem dfs树
传送门 文章目录 题意: 思路: 题意: 给你个nnn个点mmm条边的图,可以选择完成以下两个任务中的一个: (1)(1)(1)找出大小恰好为n\sqrt nn的一个独立集. (2)(2)(2)找出 ...
- Codeforces Round #731 (Div. 3) G. How Many Paths? dfs + 拓扑 + 思维
传送门 题意: 给你一张nnn个点mmm条边的图,让你对每个点确定一个编号,规则如下: (1)(1)(1) 对于不能到的点编号为000. (2)(2)(2) 对于只有一条路径能到这个点的点编号为111 ...
- Codeforces Round #453 (Div. 1) D. Weighting a Tree 构造 + dfs树
传送门 文章目录 题意: 思路: 题意: 给你一颗nnn个点的图,每个点都有一个点权cic_ici,要求你给每个边赋一个权值kik_iki,要求对于每个点与他相连的边的权值之和等于这个点的点权ci ...
- Codeforces Round #506 (Div. 3)
Codeforces Round #506 (Div. 3) 实习期间事不多,对div3 面向题解和数据编程了一波 A. Many Equal Substrings 题目链接 A题就是找后缀和前缀重合 ...
最新文章
- 简单ThreadPool实现
- las数据转pcd并显示
- python使用界面-用python编写简单ui界面窗口
- 触发器代码(更新表A数据自动更新表B字段列)
- 深入分析 Javascript 单线程
- 2015年百度之星初赛(1) --- D KPI
- 小白信用卡提额攻略,2年轻松提额20万!
- 什么是CDP(连续数据保护)?
- 部署thinkphp5框架的php,三、部署ThinkPHP5框架
- How do I create 2D water with dynamic waves?
- 在html中base的作用,html中base标签的作用是什么
- 腾讯同事要跳槽,问我背包问题具体咋回事,我直接甩给他这篇!
- Ext.Net学习笔记之动态加载TabPanel
- curl: symbol lookup error: curl: undefined symbol: curl_mime_free
- 高通QFIL烧录错误解决方法
- llS 10.0详细错误-404.0 - NotFound
- adb shell getprop/setprop
- 高尔顿钉板实验是二项分布吗?
- 优秀课程案例:使用Scratch制作坦克大战增强版!
- sql server 2014 使用sql清理日志(简单方便)
热门文章
- Modifier ‘public‘ is redundant for interface methods错误
- java des 0填充方式_DES填充方式与初始向量IV的作用
- Qt只有release
- 我php第一个页面,您的第一个 PHP 页面
- 使用js数组sort比较函数,实现按照对象的某个属性对数组进行排序
- 洛谷回文数c语言,【普及-】洛谷P1015:回文数 一种解法
- 面试官问你final、finally、finalize的区别
- Git基础操作及常见命令——详解
- 毕设日志——特征融合修改vgg16.py
- K8S中如何跨namespace 访问服务?为什么ping不通ClusterIP?