题目传送门

 /*
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. 编写一个程序,求s=1+(1+2)+(1+2+3)+…+(1+2+3+…+n)的值

    编写一个程序,求s=1+(1+2)+(1+2+3)+…+(1+2+3+…+n)的值 1 #import <Foundation/Foundation.h>  2   3 int main( ...

  2. Xn数列(codevs 1281)

    题目描述 Description 给你6个数,m, a, c, x0, n, g Xn+1 = ( aXn + c ) mod m,求Xn m, a, c, x0, n, g<=10^18 输入 ...

  3. IE11 的区别

    http://msdn.microsoft.com/zh-tw/visualc/bg182625

  4. uitableviewcell cell.accessoryType 右箭头

    实现右侧的小灰色箭头  只要将cell的accessoryType属性设置为 UITableViewCellAccessoryDisclosureIndicator就可以了. 代码为:cell.acc ...

  5. IOS开发之实现App消息推送

    转自:http://blog.csdn.net/shenjie12345678/article/details/41120637 第一部分 首先第一步当然是介绍一下苹果的推送机制(APNS)咯(ps: ...

  6. NYOJ题目1047欧几里得

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAskAAAIcCAIAAACLpKQmAAAgAElEQVR4nO3dv1LjOsMH4O8m6LkQ6l ...

  7. Android下拉刷新效果实现

    本文主要包括以下内容 自定义实现pulltorefreshView 使用google官方SwipeRefreshLayout 下拉刷新大致原理 判断当前是否在最上面而且是向下滑的,如果是的话,则加载数 ...

  8. MVC学习笔记---MVC框架执行顺序

    一.把路由添加到路由表, 二.注册ControllerBuilder(老板)和默认工厂(DefaultControllerFactory) 2.1默认工厂获取可以创建的Controller. 三.由于 ...

  9. SQLServer子查询

    in谓词子查询 select * from dbo.Worker where did in (select dID from DepartMent) 比较运算子查询 select * from Wor ...

  10. Genymotion刷入谷歌应用市场以及获取root权限

    Genymotion刷入谷歌应用市场以及获取root权限 - 推酷http://www.tuicool.com/articles/rEV3aa6 刷入gapp, arm框架,supersu的包要注意, ...