/*这道题我原本是将斜线迷宫扩大为原来的两倍,但是在这种情况下对于在斜的方向上的搜索会变的较容易出错,所以参考了别人的思路后将迷宫扩展为原来的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的更多相关文章

  1. UVA 705 Slash Maze

     Slash Maze  By filling a rectangle with slashes (/) and backslashes ( ), you can generate nice litt ...

  2. 705 - Slash Maze

    By filling a rectangle with slashes (/) and backslashes ( ), you can generate nice little mazes. Her ...

  3. UVA题目分类

    题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...

  4. (Step1-500题)UVaOJ+算法竞赛入门经典+挑战编程+USACO

    http://www.cnblogs.com/sxiszero/p/3618737.html 下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年 ...

  5. ACM训练计划step 1 [非原创]

    (Step1-500题)UVaOJ+算法竞赛入门经典+挑战编程+USACO 下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年到1年半年时间完成 ...

  6. 算法竞赛入门经典+挑战编程+USACO

    下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年到1年半年时间完成.打牢基础,厚积薄发. 一.UVaOJ http://uva.onlinej ...

  7. Backtracking algorithm: rat in maze

    Sept. 10, 2015 Study again the back tracking algorithm using recursive solution, rat in maze, a clas ...

  8. Crontab中的除号(slash)到底怎么用?

    crontab 是Linux中配置定时任务的工具,在各种配置中,我们经常会看到除号(Slash)的使用,那么这个除号到底标示什么意思,使用中有哪些需要注意的地方呢?   在定时任务中,我们经常有这样的 ...

  9. (期望)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 ...

  10. 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 ...

随机推荐

  1. C++ 拷贝构造函数 和 六大函数

    1.  C++什么时候会调用 拷贝构造函数? a.一个对象作为函数参数,以值传递的方式传入函数体: b.一个对象作为函数返回值,以值传递的方式从函数返回:(实际使用时,会被编译器优化掉) c.一个对象 ...

  2. bat 炸弹升级

    转自:http://digi.163.com/15/0320/06/AL4LP0QD0016192R.html 第1页:什么是批处理炸弹? 最近网上流传一个叫做<大哥别杀我>视频纷纷遭到网 ...

  3. LoadRunner关联函数的脚本实例--如何操作关联参数

    LoadRunner关联函数的脚本实例--如何操作关联参数 这几天一直在学习LoadRunner的VuGen编程,今天想对关联函数web_reg_save_param做详细的试验和研究: ~f6p q ...

  4. jQuery方法注意事项

    1.关于选择器中含有特殊符号 选择器中含有".","#","(","]"等特殊字符,根据W3C的规定,属性值中是不能含有 ...

  5. 51nod 1051 求最大子矩阵和

    题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1051 1051 最大子矩阵和 基准时间限制:2 秒 空间限制: ...

  6. 20145223《Java程序程序设计》第1周学习总结

    20145223 <Java程序设计>第1周学习总结 教材学习内容总结 1.JDK.JRE以及JVM的区别 JDK:撰写java程序语言的时候需要用到的编译工具 JRE:java执行环境 ...

  7. android测试点汇总

    Android的功能测试点 安装\卸载 App具体功能点 联网(默认的联网方式是什么?Wifi orSim卡?网络切换是否有相应的提示说明?飞行模式) 程序进入输入功能时,是否正常弹出键盘;键盘是否遮 ...

  8. AngularJS $http

    $http 是 AngularJS 中的一个核心服务,用于读取远程服务器的数据.在服务器上读取数据: <div ng-app="myApp" ng-controller=&q ...

  9. http://www.cnblogs.com/meiCode/p/5896239.html

    http://www.cnblogs.com/meiCode/p/5896239.html

  10. 虚拟机CentOS-mini安装完成后的网络设置

    系统环境:虚拟机, CentOS-mini,x86-64, 1. 主机名设置 涉及的文件: /etc/hostname;  /etc/sysconfig/network 1.1 在/etc/hostn ...