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/ 这题我之前写没想到迭代加深,看了题解,然后学习了这种搜索(之前我写的某题也用过,,但是不懂专业名词 囧.) 迭代加深搜索就是限制 ...
随机推荐
- Windows系统清除远程连接记录的方法
=============================== 1.点击“开始->运行”,在输入框中键入regedit并回车. 在打开的注册表编辑器中, 找到“HKEY_CURRENT_USER ...
- 堆优化的dij【模板】
#include<iostream> #include<cstdio> #include<cstring> #include<queue> using ...
- Laravel 5.1 中 Session 数据存储、访问、删除及一次性Session实例教程
1.Session的由来及其实现 HTTP协议是无状态的协议,同一个客户端的这次请求和上次请求是没有对应关系的.也就是说我们无法在服务器端确认两次请求是否是同一个用户所为,这为我们在一些应用场景中实现 ...
- Hive2:Unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient
[root@node1 ~]# hive which: no hbase in (/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bi ...
- 使用点聚 weboffice 以及vsto、 web service 实现word 的自动化文档处理
开发环境的搭建: 1.visual studio 2010 2. 点聚web office 开发步骤 1. 创建word vsto 项目 比较简单 1. 添加任务窗格 页面如下: 代码如下: 1. 使 ...
- XDomainRequest object
The XDomainRequest object has these types of members: Events Methods Properties Events The XDomainRe ...
- RESTful 知识点
REST(英文:Representational State Transfer,简称REST) 对于资源的具体操作类型,由HTTP动词表示. 常用的HTTP动词有下面五个(括号里是对应的SQL命令). ...
- php单例模式实现对象只被创建一次 mysql单例操作类
这是我在php面试题中遇到的一道试题,单例模式按字面来看就是某一个类只有一个实例,这样做的好处还是很大的,比如说数据库的连接,我们只需要实例化一次,不需要每次都去new了,这样极大的降低了资源的耗费. ...
- hadoop零基础入门之DKH安装准备
前几天去参加了一个线下的聚会,参加聚会的基本都是从事互联网工作的.会上有人提到了区块链,从而引发了一场关于大数据方面的探讨.我也是从去年才正式接触大数据,一直在学习hadoop.相信接触过hadoop ...
- 转载-JavaWeb学习总结
JavaWeb学习总结(五十三)——Web应用中使用JavaMail发送邮件 孤傲苍狼 2015-01-12 23:51 阅读:13407 评论:20 JavaWeb学习总结(五十二)——使用 ...