题意,就是根据斜线组成的迷宫,判断能够组成多少个闭环.

解法:

放大俩倍或者三倍

俩倍

\     ------->10

      01

三倍

\  ------->100

       010

       001

然后深搜,有个问题,没有判断是否成环,它竟然过了,待证明----它到底对不对

#include<stdio.h>
#include<iostream>
#include<queue>
#include<memory.h>
using namespace std;
const int MAX = 80 * 3;
int maps[MAX][MAX];
int r, c;
void dfs(int x, int y, int tr, int tc, int* total, int* ok)
{
*total = *total + 1;
maps[x][y] = 1;
if(x == 0 || x == (tr - 1) || y == 0 || y == (tc - 1))
*ok = 0;
if(x > 0 && maps[x - 1][y] == 0)
dfs(x - 1, y, tr, tc, total, ok);
if(y > 0 && maps[x][y - 1] == 0)
dfs(x, y - 1, tr, tc, total, ok);
if(x < (tr - 1) && maps[x + 1][y] == 0)
dfs(x + 1, y, tr, tc, total, ok);
if(y < (tc - 1) && maps[x][y + 1] == 0)
dfs(x, y + 1, tr, tc, total, ok); } int main()
{
freopen("d:\\1.txt", "r", stdin);
int T = 1;
while (cin >> c >> r)
{
if(r == 0 && c == 0)
return 0;
memset(maps, 0, sizeof(maps));
char cc;
for(int i = 0; i < r; i++)
{
for(int j = 0; j < c; j++)
{
cin >> cc;
if(cc == '/')
{
maps[3 * i][3 * j + 2] = 1;
maps[3 * i + 1][3 * j + 1] = 1;
maps[3 * i + 2][3 * j] = 1;
}
else if(cc == '\\')
{
maps[3 * i][3 * j] = 1;
maps[3 * i + 1][3 * j + 1] = 1;
maps[3 * i + 2][3 * j + 2] = 1;
}
}
}
int mr = 3 * r;
int mc = 3 * c;
int t = 0;
int max = 0;
for(int i = 0; i < mr; i++)
for(int j = 0; j < mc; j++)
{
if(maps[i][j] == 0)
{
int ok = 1;
int total = 0;
dfs(i, j, mr, mc, &total, &ok);
if(ok)
{
max = max > total ? max : total;
t++;
}
}
} cout << "Maze #" << T << ":" << endl;
if(t == 0)
cout << "There are no cycles." << endl;
else
cout << t << " Cycles; the longest has length " << max / 3 << "."
<< endl;
cout << endl;
T++; }
return 0;
}

  

uva-705-深搜的更多相关文章

  1. UVA 10160 Servicing Stations(深搜 + 剪枝)

    Problem D: Servicing stations A company offers personal computers for sale in N towns (3 <= N < ...

  2. UVA 165 Stamps (DFS深搜回溯)

     Stamps  The government of Nova Mareterrania requires that various legal documents have stamps attac ...

  3. HDU--杭电--1195--Open the Lock--深搜--都用双向广搜,弱爆了,看题了没?语文没过关吧?暴力深搜难道我会害羞?

    这个题我看了,都是推荐的神马双向广搜,难道这个深搜你们都木有发现?还是特意留个机会给我装逼? Open the Lock Time Limit: 2000/1000 MS (Java/Others)  ...

  4. 利用深搜和宽搜两种算法解决TreeView控件加载文件的问题。

    利用TreeView控件加载文件,必须遍历处所有的文件和文件夹. 深搜算法用到了递归. using System; using System.Collections.Generic; using Sy ...

  5. 2016弱校联盟十一专场10.3---Similarity of Subtrees(深搜+hash、映射)

    题目链接 https://acm.bnu.edu.cn/v3/problem_show.php?pid=52310 problem description Define the depth of a ...

  6. 2016弱校联盟十一专场10.2---Around the World(深搜+组合数、逆元)

    题目链接 https://acm.bnu.edu.cn/v3/problem_show.php?pid=52305 problem  description In ICPCCamp, there ar ...

  7. 2015暑假多校联合---Cake(深搜)

    题目链接:HDU 5355 http://acm.split.hdu.edu.cn/showproblem.php?pid=5355 Problem Description There are m s ...

  8. 深搜+回溯 POJ 2676 Sudoku

    POJ 2676 Sudoku Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17627   Accepted: 8538 ...

  9. 深搜+DP剪枝 codevs 1047 邮票面值设计

    codevs 1047 邮票面值设计 1999年NOIP全国联赛提高组  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond 题目描述 Description ...

  10. 【wikioi】1049 棋盘染色(迭代深搜)

    http://www.wikioi.com/problem/1049/ 这题我之前写没想到迭代加深,看了题解,然后学习了这种搜索(之前我写的某题也用过,,但是不懂专业名词 囧.) 迭代加深搜索就是限制 ...

随机推荐

  1. Python开源应用系统

    1.股票量化系统 https://github.com/moyuanz/DevilYuan 2.基于Echarts和Tushare的股票视觉化应用 https://github.com/Seedarc ...

  2. js代码中碰到的函数

    第一个--->字符串的截取substring()方法 substring(a,b)--->[a,b)区间截取字符.下标从0开始.从a下标开始,截取到b下标的前一个字符.返回一个新的字符串 ...

  3. curl 知识点

    curl :command line tool and library for transferring data with URLs curl 命令,常用缩写: curl 命令 缩写 说明 curl ...

  4. 51nod 1965 奇怪的式子——min_25筛

    题目:http://www.51nod.com/Challenge/Problem.html#!#problemId=1965 考虑 \( \prod_{i=1}^{n}\sigma_0^i \) \ ...

  5. Vue 介绍

    1. 条件 效果图. 如果seen为false,文字将消失 2. 循环 script里定义数据 效果 3. 事件处理 效果如下图, hello world被逆转了

  6. mySQL教程 第1章 数据库设计

    E-R设计 很多同学在学SQL语句时,觉得非常困难,那是因为你在学一个你根本不了解的数据库,数据库中的表不是你设计的,表与表之间的关系你不明白.因此在学SQL语句之前,先介绍一下数据库设计. 下面举例 ...

  7. yield对性能提升的一次小小测试

    生成器提供了一种更容易的方法来实现简单的对象迭代,相比较定义类实现 Iterator 接口的方式,性能开销和复杂性大大降低.生成器允许你在 foreach 代码块中写代码来迭代一组数据而不需要在内存中 ...

  8. 【appium】根据id定位元素

    目前没有尝试成功,等成功后补充 id=Resource Id,可以通过UIAutomatorViewer获得.如果目标设备的API Level低于18则UIAutomatorViewer不能获得对应的 ...

  9. Git断点续传和离线增量更新的实现

    cnblogs官方支持Markdown写博客了,亲测一下. ____ 什么是Bundle文件 Bundle文件是在packfile文件的基础上增加了代码库的元信息.通俗的说bundle文件就是一个便携 ...

  10. winform 控件没有Cursor属性时的处理办法

    开发程序时,有时我们需要鼠标滑过空件时鼠标变成手型,这样触发动作更为贴近实际.但是有的控件不存在Cursor这个属性,就需要我们自己实现. 具体方法: /// <summary> /// ...