uva705--slash maze
/*这道题我原本是将斜线迷宫扩大为原来的两倍,但是在这种情况下对于在斜的方向上的搜索会变的较容易出错,所以参考了别人的思路后将迷宫扩展为原来的3倍,这样就变成一般的迷宫问题了*/
#include"iostream"
#include"stdio.h"
#include"algorithm"
#include"cmath"
#include"string.h"
#include"ctype.h"
#include"queue"
#include"map"
#define mx 300
using namespace std;
int w,h;
int maze[mx][mx];
char m;
int dir[][]={{,},{-,},{,},{,-}};
int visited[mx][mx];
int cnt;//记录圈的个数
int mxlen;//记录最长圈的长度
int len;//记录当前圈的长度
int flag;//标记是否构成圈
bool judge(int x,int y)
{
if(x>=&&x<*h&&y>=&&y<*w) return true;//判断点是否出界
else return false;
}
void dfs(int x,int y)
{
int k,dx,dy;
for(k=;k<;k++)
{
dx=x+dir[k][];
dy=y+dir[k][];
if(judge(dx,dy))
{
if(!visited[dx][dy]&&!maze[dx][dy])
{
visited[dx][dy]=;
len++;
dfs(dx,dy);
}
}
else //边界上的点肯定不构成圈。。。
{flag=;}
// cout<<len<<endl;
}
}
int main()
{
int i,j,k;
int count1=;
while(cin>>w>>h,w||h)
{
count1++;
memset(maze,,sizeof(maze));
for(i=;i<h;i++)
{
getchar();
for(j=;j<w;j++)
{
scanf("%c",&m);
if(m=='/')
{
maze[*i+][*j]=;maze[*i+][*j+]=;maze[*i][*j+]=;
}
else
{
maze[*i][*j]=;maze[*i+][*j+]=;maze[*i+][*j+]=;
}
}
}
for(i=;i<*h;i++)
for(j=;j<*w;j++)
{visited[i][j]=maze[i][j];}
mxlen=;
cnt=;
for(i=;i<*h;i++)
{
for(j=;j<*w;j++)
{
if(maze[i][j]==&&!visited[i][j])
{
len=;
flag=;
visited[i][j]=;
dfs(i,j);
if(flag)
{
cnt++;
if(len>mxlen) mxlen=len;
}
}
}
}
cout<<"Maze #"<<count1<<":"<<endl;
if(cnt==) cout<<"There are no cycles."<<endl<<endl;
else
cout<<cnt<<" Cycles; "<<"the longest has length "<<mxlen/<<'.'<<endl<<endl;
}
return ;
}
uva705--slash maze的更多相关文章
- UVA 705 Slash Maze
Slash Maze By filling a rectangle with slashes (/) and backslashes ( ), you can generate nice litt ...
- 705 - Slash Maze
By filling a rectangle with slashes (/) and backslashes ( ), you can generate nice little mazes. Her ...
- UVA题目分类
题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...
- (Step1-500题)UVaOJ+算法竞赛入门经典+挑战编程+USACO
http://www.cnblogs.com/sxiszero/p/3618737.html 下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年 ...
- ACM训练计划step 1 [非原创]
(Step1-500题)UVaOJ+算法竞赛入门经典+挑战编程+USACO 下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年到1年半年时间完成 ...
- 算法竞赛入门经典+挑战编程+USACO
下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年到1年半年时间完成.打牢基础,厚积薄发. 一.UVaOJ http://uva.onlinej ...
- Backtracking algorithm: rat in maze
Sept. 10, 2015 Study again the back tracking algorithm using recursive solution, rat in maze, a clas ...
- Crontab中的除号(slash)到底怎么用?
crontab 是Linux中配置定时任务的工具,在各种配置中,我们经常会看到除号(Slash)的使用,那么这个除号到底标示什么意思,使用中有哪些需要注意的地方呢? 在定时任务中,我们经常有这样的 ...
- (期望)A Dangerous Maze(Light OJ 1027)
http://www.lightoj.com/volume_showproblem.php?problem=1027 You are in a maze; seeing n doors in fron ...
- Make Notepad++ auto close HTML/XML tags after the slash(the Dreamweaver way)
I've been looking for a Notepad++ plugin that can close HTML/XML tags after a slash just like the wa ...
随机推荐
- 一定要学会paxos算法!
paxos算法 http://blog.csdn.net/dellme99/article/details/14162159
- 【转】HTML网页中插入视频各种方法
现在如果要在页面中使用video标签,需要考虑三种情况,支持Ogg Theora或者VP8(如果这玩意儿没出事的话)的(Opera.Mozilla.Chrome),支持H.264的(Safari.IE ...
- 【转】Kylin实践之使用Hive视图
http://blog.csdn.net/yu616568/article/details/50548967 为什么需要使用视图 Kylin在使用的过程中使用hive作为cube的输入,但是有些情况下 ...
- ASP.Net MVC开发基础学习笔记(4):校验、AJAX与过滤器
一.校验 — 表单不是你想提想提就能提 1.1 DataAnnotations(数据注解) 位于 System.ComponentModel.DataAnnotations 命名空间中的特性指定对数据 ...
- 关于DOM
前言 DOM的作用是将网页转为一个javascript对象,从而可以使用javascript对网页进行各种操作(比如增删内容).浏览器会根据DOM模型,将HTML文档解析成一系列的节点,再由这些节点组 ...
- UVa12264 Risk(最大流)
题目 Source https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...
- js中typeof与instanceof区别
今天写JS代码,遇到动态生成多个名称相同的input复选按钮 需要判断其是否是数组,用到了if (typeof(document.MapCheckMgr.checkid)!="undefin ...
- uva 107 - The Cat in the Hat
The Cat in the Hat Background (An homage to Theodore Seuss Geisel) The Cat in the Hat is a nasty c ...
- ural 1251. Cemetery Manager
1251. Cemetery Manager Time limit: 1.0 secondMemory limit: 64 MB There is a tradition at the USU cha ...
- 使用 Git 和 Visual Studio Online 进行版本控制
参考资料: 在开发计算机上设置 Git(配置.创建.克隆.添加) 关于 Git 和 Visual Studio Online 是什么请自行百度 转载请注明来源: http://www.cnblogs. ...