题目传送门

 /*
DFS:每个点四处寻找,判断是否与前面的颜色相同,当走到已走过的表示成一个环
*/
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <map>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
using namespace std; const int MAXN = 1e6 + ;
const int INF = 0x3f3f3f3f;
int dx[] = {, -, , };
int dy[] = {, , , -};
char a[][];
int used[][];
int n, m; bool DFS(int x, int y, int px, int py, char ch)
{
used[x][y] = ;
for (int i=; i<=-; ++i)
{
int tx = x + dx[i];
int ty = y + dy[i];
if (tx == px && ty == py) continue;
if (tx >= && tx <= n- && ty >= && ty <=m- && a[tx][ty] == ch)
{
if (used[tx][ty]) return true;
if (DFS (tx, ty, x, y, ch)) return true;
}
} return false;
} int main(void)
{
//freopen ("B.in", "r", stdin); while (cin >> n >> m)
{
memset (used, , sizeof (used));
for (int i=; i<=n-; ++i)
{
scanf ("%s", &a[i]);
} bool flag = false;
for (int i=; i<=n-; ++i)
{
for (int j=; j<=m-; ++j)
{
if (!used[i][j])
{
if (DFS (i, j, -, -, a[i][j]))
{
puts ("Yes"); flag = true; break;
}
}
}
if (flag) break;
} if (!flag) puts ("No");
} return ;
}

DFS Codeforces Round #290 (Div. 2) B. Fox And Two Dots的更多相关文章

  1. 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 ...

  2. Codeforces Round #290 (Div. 2) B. Fox And Two Dots(DFS)

    http://codeforces.com/problemset/problem/510/B #include "cstdio" #include "cstring&qu ...

  3. 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 ...

  4. Codeforces Round #290 (Div. 2) E. Fox And Dinner 网络流建模

    E. Fox And Dinner time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  5. 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 ...

  6. 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 ...

  7. 找规律 Codeforces Round #290 (Div. 2) A. Fox And Snake

    题目传送门 /* 水题 找规律输出 */ #include <cstdio> #include <iostream> #include <cstring> #inc ...

  8. 拓扑排序 Codeforces Round #290 (Div. 2) C. Fox And Names

    题目传送门 /* 给出n个字符串,求是否有一个“字典序”使得n个字符串是从小到大排序 拓扑排序 详细解释:http://www.2cto.com/kf/201502/374966.html */ #i ...

  9. DFS Codeforces Round #306 (Div. 2) B. Preparing Olympiad

    题目传送门 /* DFS: 排序后一个一个出发往后找,找到>r为止,比赛写了return : */ #include <cstdio> #include <iostream&g ...

随机推荐

  1. 2048控制台程序:一份帝国理工C++作业

    #include <fstream> #include <vector> #include <iostream> #include <string> u ...

  2. 在CMD窗口中使用javac和java命令进行编译和执行带有包名的具有继承关系的类

    一.背景 最近在使用记事本编写带有包名并且有继承关系的java代码并运行时发现出现了很多错误,经过努力一一被解决,今天我们来看一下会遇见哪些问题,并给出解决办法. 二.测试过程 1.父类代码 pack ...

  3. 数据存储--sqlite总结

    SQLite SQLite(轻量级的数据库,关系型数据库) 辅助工具:Navicat Premium 等 原理:ios针对存储问题封装了sqlite数据库(c语言数据库). 1 app获取沙盒地址命名 ...

  4. Hive学习路线图(转)

    Hadoophivehqlroadmap学习路线图   1 Comment Hive学习路线图 Hadoop家族系列文章,主要介绍Hadoop家族产品,常用的项目包括Hadoop, Hive, Pig ...

  5. Ubuntu 14.04 Trusty安装java环境

    原文:Install Oracle Java 6, 7, or 8 in Ubuntu 14.04 Trusty 命令如下: sudo add-apt-repository ppa:webupd8te ...

  6. WMI测试

    https://social.msdn.microsoft.com/Forums/windowshardware/zh-CN/c5af7959-95d3-4e1b-ab40-96a2a31c2af2/ ...

  7. Notice: Only variable references should be returned by reference(PHP版本兼容性问题)

    摘自:http://sushener.spaces.live.com/blog/cns!BB54050A5CFAFCDD!435.entry PHP5一个很让人恼火的一点就是BC(向后兼容)不是很理想 ...

  8. ASP.NET Web Api 使用CacheCow和ETag缓存资源(转载)

    转载地址:http://www.cnblogs.com/fzrain/p/3618887.html 前言 本文将使用一个开源框架CacheCow来实现针对Http请求资源缓存,本文主要介绍服务器端的缓 ...

  9. dbca:Exception in thread "main" java.lang.UnsatisfiedLinkError: get

    在64位的操作系统安装oracle10g 软件安装完成后,使用dbca建库的时候报下面的错: $ dbcaUnsatisfiedLinkError exception loading native l ...

  10. 一个简单的Promise 实现

    用了这么长时间的promise,也看了很多关于promise 的文章博客,对promise 算是些了解.但是要更深的理解promise,最好的办法还是自己实现一个. 我大概清楚promise 是对异步 ...