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

    SOA简介 SCA实现SOA的最佳方式 Apache开源框架Tuscany实现SCA架构 SOA简单描述: SOA(Service-Oriented Architecture)面向服务的体系架构.为了 ...

  2. 【MongoDB】1.安装--以及简单使用

    第一次接触MongoDB    参考&粘贴:http://jingyan.baidu.com/article/ed15cb1b52b8661be2698162.html 一.安装 1.首先去官 ...

  3. DrawerLayout的使用

    一:首先是DrawerLayout的布局 <android.support.v4.widget.DrawerLayout android:id="@+id/drawer_layout& ...

  4. css样式—字体垂直、水平居中

    “来,老板娘,给个div瞅瞅”: “好的,宇哥,来了了了”: <div class="tt">啦啦啦</div> “给各样啊,我去”: “是”: .tt{ ...

  5. Dapper ORM 用法—Net下无敌的ORM(转)

    假如你喜欢原生的Sql语句,又喜欢ORM的简单,那你一定会喜欢上Dapper这款ROM.点击下载Dapper的优势:1,Dapper是一个轻型的ORM类.代码就一个SqlMapper.cs文件,编译后 ...

  6. 余数 2015广工校赛 C 魔幻任务

    题目传送门 题意:问n位最小能整除47的数字 分析:打表发现前面都是100000...,后两位就是100000%47后到47的距离,就是快速幂求1000000%47的值,47-它就是后两位 #incl ...

  7. three.js 场景入门

    <!DOCTYPE html> <html> <head> <title>Example 01.02 - First Scene</title&g ...

  8. EF框架step by step(9)—Code First Fluent API

    在上一篇中,讲述了用数据特性的方式来标识实体与数据表之间的映射关系,在Code First方法中,还可以通过Fluent API的方式来处理实体与数据表之间的映射关系. 要使用Fluent API必须 ...

  9. The 2015 China Collegiate Programming Contest K Game Rooms hdu 5550

    Game Rooms Time Limit: 4000/4000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total ...

  10. 怎样测试TCP&UDP端口

    TCP端口大家都知道,比如80端口,可以使用 telnet ip 80,来验证端口是否正常监听,那UDP端口是否可以同样测试呢?详细如下: 下面我们来进行测试,123端口是服务器42.11.12.13 ...