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 ...
随机推荐
- hdu3535 背包大杂汇
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=3535 //不想写题解,这道题让我对背包的理解更深了,我相信我不会忘记的.... 代码: # ...
- DSP using MATLAB 示例Example3.9
用到的性质 上代码: n = 0:100; x = cos(pi*n/2); k = -100:100; w = (pi/100)*k; % freqency between -pi and +pi ...
- js简版图片左右切换功能
function leftMove(obj,direction,lis){ var num = 0; var liWidth = lis[0].offsetWidth; setInterval(fun ...
- 6754 Keyboard of a Mobile Telephone
/*实践再次说明ch=getchar()的速度非常慢*/ /*大水题,不解释*/ #include<stdio.h> #include<string.h> int main() ...
- tomcat 部署spring工程乱码解决方案
tomcat的server.xml文件,Connector标签增加useBodyEncodingForURI="true"属性 web.xml如下配置 <filter> ...
- React版本修改内容
React新版本(0.12.2)在2014年12月18日发布,对比了我之前用的v0.11.2版本改动很大,基本的写法被扩展,让我顿时感觉自己又要重新开始.坑啊~ 事已至此,必须重新适应,首先我们来看看 ...
- Modify a Stored Procedure using SQL Server Management Studio
In Object Explorer, connect to an instance of Database Engine and then expand that instance. Expand ...
- Spring In Action ③
第三章 最小化Spring xml配置 自动装配(autowiring) 自动检测(autodiscovery) 自动装配 byName.byType.constructor autodetec ...
- HDU 4405 (概率DP)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4405 题目大意:飞行棋.如果格子不是飞行点,扔骰子前进.否则直接飞到目标点.每个格子是唯一的飞行起点 ...
- requestAnimationFrame制作动画:旋转风车
在以往,我们在网页上制作动画效果的时候,如果是用javascript实现,一般都是通过定时器和间隔来实现的,出现HTML5之后,我们还可以用CSS3 的transitions和animations很方 ...