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

解法:

放大俩倍或者三倍

俩倍

\     ------->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. STM32中断定时,控制LED灯

    #include "led.h" void TIM3_Int_Init(u16 arr,u16 psc) { TIM_TimeBaseInitTypeDef TIM_TimeBas ...

  2. 怎样取消老毛桃软件赞助商---只需在输入框中输入老毛桃官网网址“laomaotao.org”

    来源:www.laomaotao.org 时间:2015-01-29 在众多网友和赞助商的支持下,迄今为止,老毛桃u盘启动盘制作工具已经推出了多个版本.如果有用户希望取消显示老毛桃软件中的赞助商,那不 ...

  3. RequireJs 与 SeaJs的相同之处与区别

    相同之处: RequireJS 和 Sea.js 都是模块加载器,倡导模块化开发理念,核心价值是让 JavaScript 的模块化开发变得简单自然. 不同之处: 定位有差异.RequireJS 想成为 ...

  4. HDU1423 Greatest Common Increasing Subsequence

    题意 如标题. \(|s1|,|s2| \leq 500\) 分析 既然是dp问题的组合,那么考虑dp. 定义状态f(i,j)表示对第一个序列s1的前i个和第二个序列s2的前j个元素求最长上升公共子序 ...

  5. day27 python学习 logging

    logging模块 函数式简单配置 import logging logging.debug('debug message') logging.info('info message') logging ...

  6. j2ee使用struts实现用户的登陆及注冊

    用户名: 密码: <%-- 使用struts标签 --%> <%-- --%>

  7. [unity3d]角色控制器组件相互间不碰撞

    RPG游戏会有这种需求. 队友之间,玩家之间.玩家与怪物之间,都有可能须要不能碰撞.怎样实现?这个问题困恼了一段时间,昨天在网上看到解答的方法: 这里举例玩家和怪物之间: 1,填加2个不同的层级mon ...

  8. VisualSVN安装配置与使用

    VisualSVN安装配置与使用 1.  所选服务器安装包:VisualSVN-Server-2.1.3.msi. 2.  客户端安装包:TortoiseSVN-1.6.2.16344-win32-s ...

  9. NOSQL之MEMCACHE

    Memcached是一个自由开源的,高性能,分布式内存对象缓存系统.Memcached是一个自由开源的,高性能,分布式内存对象缓存系统.Memcached是一种基于内存的key-value存储,用来存 ...

  10. java Scanner中的hasNext()方法

    hasNext()方法判断输入(文件.字符串.键盘等输入流)是否还有下一个输入项,若有,返回true,反之false. Scanner sc = new Scanner(new File(" ...