=================================================================================================================================
题意:是能否找到一连串同样的字母至少四个形成循环(贯通)
通过dfs 按照相同的字母遍历一遍, 且阻止其走回头路,那么深搜之后再次搜到被标记的点,则肯定就形成了循环。
详情解释,见代码。
=================================================================================================================================
 代码:
 #include<bits/stdc++.h>
using namespace std;
int n,m;
char Map[][];
bool book[][];
bool flag;
void dfs(int y,int x,int rey,int rex)
{
for(int i =;i<=;i++)
{
int ty=y,tx=x;
if(i==) ty++; //四个方向
if(i==) ty--;
if(i==) tx++;
if(i==) tx--;
if(ty<||ty>n||tx<||tx>m) continue;
if(ty==rey&&tx==rex) continue; //阻止往回走
if(Map[y][x]==Map[ty][tx]) //确保是相同的字母
{
if(book[ty][tx]==) {flag = ;break;}
book[ty][tx]=;
dfs(ty,tx,y,x);
}
}
return;
}
int main()
{
scanf("%d %d",&n,&m);
for(int y = ;y<=n;++y)
for(int x=;x<=m;++x)
{
cin>>Map[y][x];
} for(int y = ;y<=n;++y)
{
for(int x=;x<=m;++x)
{
if(book[y][x]==) continue;
book[y][x]=; //走过的点都标记上
dfs(y,x,,);
if(flag==) break;
}
if(flag==) break;
}
printf(flag==?"Yes\n":"No\n");
}

17-比赛2 F - Fox And Two Dots (dfs)的更多相关文章

  1. CF Fox And Two Dots (DFS)

    Fox And Two Dots time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

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

  3. D - Fox And Two Dots DFS

    Fox Ciel is playing a mobile puzzle game called "Two Dots". The basic levels are played on ...

  4. CodeForces - 510B Fox And Two Dots (bfs或dfs)

    B. Fox And Two Dots time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  5. B. Fox And Two Dots

    B. Fox And Two Dots time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  6. Fox And Two Dots

    B - Fox And Two Dots Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I6 ...

  7. CF510B Fox And Two Dots(搜索图形环)

    B. Fox And Two Dots time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  8. 比赛安排(穷举法或dfs)

    比赛安排 时间限制: 1 Sec  内存限制: 125 MB提交: 11  解决: 10[提交][状态][讨论版][命题人:外部导入] 题目描述 设有2n(n<=6)个球队进行单循环比赛,计划在 ...

  9. CF 510b Fox And Two Dots

    Fox Ciel is playing a mobile puzzle game called "Two Dots". The basic levels are played on ...

随机推荐

  1. struts 上传文件 Dynavalidatorform 实例

    一.相关jar包     一个空struts工程的jar包:    另上传文件的两个jar包: 二.页面 1.上传页面upload.jsp <%@ page language="jav ...

  2. 计算结构体、数组、指针的sizeof

    1. 结构体的sizeof 题目: sturct aa{ in num; char name[10];}; struct bb{ int a; float b; struct aa c;}; stru ...

  3. vos忙时闲时费率不一样怎么设置

    问题: 现有一客户要求上午闲时由原来的9:00追加到9:30 即: 9:30——12:00为忙时 14:00——18:00为忙时 其他为闲时 忙时费率为0.04元即4分 闲时费率为0.025元即2分5 ...

  4. 概念:详细讲解url和路由概念

    例如:一个网址为 http://www.abc.com/aa 定义:/aa = bb/cc/dd 那么:http://www.abc.com/aa就是一个url,那么我们可以得出:网址=url 而当我 ...

  5. LA 3708 墓地雕塑

    题目链接:https://vjudge.net/contest/132704#problem/D 题意:一个长度为10000的园上,均匀分布n个雕塑,现在要加入m个雕塑,这样原先的就可能会移动,求移动 ...

  6. PHP编译安装时常见错误及解决办法,大全

    1.   configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution ...

  7. [ difflib] simple1.py

    #!/usr/bin/env python # _*_ coding:utf-8 _*_ import difflib text1 = """text1: # 定义字符串 ...

  8. linq 查询的两种方法 (在EF model中实现)

    众所周知:linq查询有两种方式 1.通过linq表达式查询 2.是通过linq方法查询 代码中 每一步都有注释

  9. 图像上采样(图像插值)增取样(Upsampling)或内插(Interpolating)下采样(降采样),

    缩小图像(或称为下采样(subsampled)或降采样(downsampled))的主要目的有两个:1.使得图像符合显示区域的大小:2.生成对应图像的缩略图.放大图像(或称为上采样(upsamplin ...

  10. Vuex基础-Action

    在文章开始之前,再次强调一句:Vuex会把getter mutations action不管是在模块定义的还是在根级别定义的 都会注册在全局 官网API地址:https://vuex.vuejs.or ...