DFS Codeforces Round #290 (Div. 2) B. Fox And Two Dots
/*
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的更多相关文章
- 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 ...
- Codeforces Round #290 (Div. 2) B. Fox And Two Dots(DFS)
http://codeforces.com/problemset/problem/510/B #include "cstdio" #include "cstring&qu ...
- 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) E. Fox And Dinner 网络流建模
E. Fox And Dinner time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- 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) A. Fox And Snake 水题
A. Fox And Snake 题目连接: http://codeforces.com/contest/510/problem/A Description Fox Ciel starts to le ...
- 找规律 Codeforces Round #290 (Div. 2) A. Fox And Snake
题目传送门 /* 水题 找规律输出 */ #include <cstdio> #include <iostream> #include <cstring> #inc ...
- 拓扑排序 Codeforces Round #290 (Div. 2) C. Fox And Names
题目传送门 /* 给出n个字符串,求是否有一个“字典序”使得n个字符串是从小到大排序 拓扑排序 详细解释:http://www.2cto.com/kf/201502/374966.html */ #i ...
- DFS Codeforces Round #306 (Div. 2) B. Preparing Olympiad
题目传送门 /* DFS: 排序后一个一个出发往后找,找到>r为止,比赛写了return : */ #include <cstdio> #include <iostream&g ...
随机推荐
- JS 保留两位小数问题收集
1.使用四舍五入的方法,保留小数点后的两位小数: toFixed里面的参数表示保留的小数的位数,范围是0-20,超过20位就会报错了 <script> var num=22.127456; ...
- iOS第三方分享-ShareSDK
网址链接:http://mob.com/Download/detail?type=1&plat=2 由于新版的简单分享很多功能都有,而且打包后体积比全版本的少了几M所以在这里用这个 1.在官网 ...
- Java动态代理一Proxy
什么是动态代理? 动态代理可以提供对另一个对象的访问,同时隐藏实际对象的具体事实.代理一般会实现它所表示的实际对象的接口.代理可以访问实际对象,但是延迟实现实际对象的部分功能,实际对象实现系统的实际功 ...
- 20145206《Java程序设计》第9周学习总结
20145206 <Java程序设计>第9周学习总结 教材学习内容总结 第十六章 整合数据库 JDBC是用于执行SQL的解决方案,开发人员使用JDBC的标准接口,数据库厂商则对接口进行操作 ...
- sql server 对象资源管理器(一)
当需要查看具体数据库的所有用户表.存储过程等创建修改等脚本的时候,可以借用视图中的对象资源管理器的详细信息里面获取. 具体操作如下图所示:
- jQuery 操作复选框(checkbox) attr checked不起作用
参考资料 http://www.paobuke.com/develop/javascript/pbk849.html 这天用到jQuery功能,想实现一个简单的复选框动态全选或全不选,结果测试发现 ...
- 解决IIS7、IIS7.5中时间格式显示的问题
今天在用IIS7的时候发现一个关于时间格式的问题,当我在ASP中使用now()时间函数的时候,日期是以"/"来分隔,而不是以"-"来分隔的,使得我在运行程序的时 ...
- SQLServer子查询
in谓词子查询 select * from dbo.Worker where did in (select dID from DepartMent) 比较运算子查询 select * from Wor ...
- Python 打开目录与指定文件
Python打开外部文件有很多方法, os.popen打开外部程序,但发现只能打开文件所在目录的文件 os.system可打开外部文件os.system(command) command 要执行的命令 ...
- [LeetCode] Search Insert Position
Given a sorted array and a target value, return the index if the target is found. If not, return the ...