uva-705-深搜
题意,就是根据斜线组成的迷宫,判断能够组成多少个闭环.
解法:
放大俩倍或者三倍
俩倍
\ ------->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-深搜的更多相关文章
- UVA 10160 Servicing Stations(深搜 + 剪枝)
Problem D: Servicing stations A company offers personal computers for sale in N towns (3 <= N < ...
- UVA 165 Stamps (DFS深搜回溯)
Stamps The government of Nova Mareterrania requires that various legal documents have stamps attac ...
- HDU--杭电--1195--Open the Lock--深搜--都用双向广搜,弱爆了,看题了没?语文没过关吧?暴力深搜难道我会害羞?
这个题我看了,都是推荐的神马双向广搜,难道这个深搜你们都木有发现?还是特意留个机会给我装逼? Open the Lock Time Limit: 2000/1000 MS (Java/Others) ...
- 利用深搜和宽搜两种算法解决TreeView控件加载文件的问题。
利用TreeView控件加载文件,必须遍历处所有的文件和文件夹. 深搜算法用到了递归. using System; using System.Collections.Generic; using Sy ...
- 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 ...
- 2016弱校联盟十一专场10.2---Around the World(深搜+组合数、逆元)
题目链接 https://acm.bnu.edu.cn/v3/problem_show.php?pid=52305 problem description In ICPCCamp, there ar ...
- 2015暑假多校联合---Cake(深搜)
题目链接:HDU 5355 http://acm.split.hdu.edu.cn/showproblem.php?pid=5355 Problem Description There are m s ...
- 深搜+回溯 POJ 2676 Sudoku
POJ 2676 Sudoku Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 17627 Accepted: 8538 ...
- 深搜+DP剪枝 codevs 1047 邮票面值设计
codevs 1047 邮票面值设计 1999年NOIP全国联赛提高组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题目描述 Description ...
- 【wikioi】1049 棋盘染色(迭代深搜)
http://www.wikioi.com/problem/1049/ 这题我之前写没想到迭代加深,看了题解,然后学习了这种搜索(之前我写的某题也用过,,但是不懂专业名词 囧.) 迭代加深搜索就是限制 ...
随机推荐
- STM32 PWM输出(映射)
STM32 的定时器除了 TIM6 和 7.其他的定时器都可以用来产生 PWM 输出.其中高级定时器 TIM1 和 TIM8 可以同时产生多达 7 路的 PWM 输出.而通用定时器也能同时产生多达 4 ...
- XML教程、语法手册、数据读取方式大全
XML简单易懂教程 本文提供全流程,中文翻译.Chinar坚持将简单的生活方式,带给世人!(拥有更好的阅读体验 -- 高分辨率用户请根据需求调整网页缩放比例) 一 XML --数据格式的写法 二 Re ...
- 51Nod 1002:数塔取数问题(DP)
1002 数塔取数问题 基准时间限制:1 秒 空间限制:131072 KB 分值: 5 难度:1级算法题 收藏 关注 一个高度为N的由正整数组成的三角形,从上走到下,求经过的数字和的最大值. 每 ...
- C# [ModelName]标记 模型,类名称重复。
前几天遇到一个不算bug的bug 记录分享一下 出错情况 webapi 程序会自带一个模板 如图 点某一个接口进去后 出错原因 model实体中出现了名称一样的(并不会影响程 ...
- ASP.NET MVC配置Redis服务
===================== 1.下载并安装Redis.官网并未提供Windows安装版,所以去Github 下载 下载地址: https://github.com/MicrosoftA ...
- 【java规则引擎】《Drools7.0.0.Final规则引擎教程》第4章 4.3 定时器
定时器 规则用基于 interval(间隔)和cron的定时器(timer),替代了被标注过时的duration 属性.timer属性的使用示例: timer ( int: <initial d ...
- Spring MVC学习回顾
Spring MVC是现在新项目中使用最多的MVC框架,超越了Structs2成为MVC框架的首选.今天抽时间看了4.2.x的官网翻译文档及相关代码,博客,将印象比较深的几点记录一下. 一.应用Spr ...
- tomcat源码阅读之单点登录
一.SSO概念: 单点登录,Single Sign-On,简写为 SSO,是一个用户认证的过程,允许用户一次性进行认证后,就可访问系统中不同的应用:而无需要访问每个应用时,都重新输入用户和密码. 实现 ...
- ERROR 1130 (HY000): Host '192.168.20.165' is not allowed to connect to this MySQL server
问题 远程连接mysql时遇到如下问题: ERROR 1130 (HY000): Host '192.168.20.165' is not allowed to connect to this MyS ...
- keepalived的配置详解(非常详细)
keepalived的配置详解(非常详细) 2017-01-22 15:24 2997人阅读 评论(0) 收藏 举报 分类: 运维学习(25) 转载自:http://blog.csdn.net ...