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/ 这题我之前写没想到迭代加深,看了题解,然后学习了这种搜索(之前我写的某题也用过,,但是不懂专业名词 囧.) 迭代加深搜索就是限制 ...
随机推荐
- apache配置禁止访问某些文件/目录
我们来看俩段通常对上传目录设置无权限的列子,配置如下: 代码如下: ? 1 2 3 4 5 6 <Directory "/var/www/upload"> <Fi ...
- NOSQL之MEMCACHE
Memcached是一个自由开源的,高性能,分布式内存对象缓存系统.Memcached是一个自由开源的,高性能,分布式内存对象缓存系统.Memcached是一种基于内存的key-value存储,用来存 ...
- Nginx+redis部署tomcat集群
一.部署环境: 两个tomcat实例部署在Ubuntu 14上,IP地址分别为192.168.1.110和192.168.1.111,Nginx和redis部署在windows7上,IP地址为192. ...
- 【转】每天一个linux命令(30): chown命令
原文网址:http://www.cnblogs.com/peida/archive/2012/12/04/2800684.html chown将指定文件的拥有者改为指定的用户或组,用户可以是用户名或者 ...
- TNS-12535 TNS-00505的处理方法
原文地址:TNS-12535 TNS-00505的处理方法 作者:wzq609 硬件说明: 操作系统版本:ORACLE LINUX 6.3 64位 数据库版本:11.2.0.3 64位 问题说明 ...
- linQ to sql 查询生成的sql语句
1. 如果是控制台应用,直接 db.Log = Console.Out; 2.其他应用则用如下语句: StringBuilder sql = new StringBuilder(); db.Log ...
- mysql 微信用户昵称emoji 完整保存
微信用户昵称现在丰富多样,一些个性的名称中经常包含有特殊字符,以及emoji表情.起先,我总以为MySQL只能保存纯文本数据.但其实mysql(5.7版本)已非常强大,完整保存微信用户昵称(emoji ...
- Django 书籍分享(PDF)
轻量级Django 链接:https://pan.baidu.com/s/1FD5zdRIkzHI44SZ54fjt6Q 密码:6z50 精通Django 链接:https://pan.baidu.c ...
- 分析报告:云之家V9 VS 钉钉3.5
http://news.yesky.com/hotnews/1/244252501.shtml 1.市场调研 1.1 企业需求 笔者所在单位是一家中型企业,企业流程和信息化基础较为成熟.随着移动互联网 ...
- UI设计心得
旁观型ui.追求一种无所不在,同时低调退隐的,奢华的存在感.内容由用户自己去搜索,浏览,构建,召唤,或是随着信息世界的某种外界趋势自然产生,ui作为始终凌驾于用户之上的高高在上的守护神,随时起到中承, ...