1566: The Maze Makers

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 90  Solved: 33
[Submit][Status][Web Board]

Description

The Maze Makers is a publisher of puzzle books. One of their most popular series is maze books. They have a program that generates rectangular two-dimensional mazes like the one shown in Figure 1. The rules for these mazes are: (1) A maze has exactly two exterior cell walls missing, opening to two distinct terminal cells, (2) starting from any one cell, all other cells are reachable, (3) between any two cells in the maze there is exactly one simple path. Formally, a path is a sequence of cells where each cell and its successor on the path share an edge without a wall. A simple path is a path that never repeats a cell.

The Maze Maker program uses hexadecimal digits to encode the walls and passages of a maze. For each cell in the maze there is a corresponding hex digit. As shown in Figure 2, the 1's and 0's in the 4 digit binary representation of a hex digit correspond to the walls (1's) and passages (0's) for each cell in the maze. For example, the binary encoding for the hex digit B is 1011. Starting at the top of the cell and moving clockwise around it, this digit represents a cell with a wall at the top, a passage to the right and walls at the bottom and to the left. A path between two maze cells successively moves one cell up, down, left or right, going through passages only.

Figure 1: Sample Maze

Figure 2: Hex Code for Walls and Passageways

Figure 3: Maze with Cell Labels

Figure 3 shows the sample maze with the hexadecimal labels in each cell. For example, the hexadecimal digit E in the top-right cell indicates that it has a wall above it, to its right, below it, yet a passageway to its left. The hexadecimal digit 8 to its left indicates that its cell has only a wall above it. The inputs will always be self-consistent, in that the hexadecimal digits in neighboring cells will agree on whether they share a wall or passageway, and each input will always have precisely two terminal cells, each with one missing exterior wall.

Our sample maze is a legitimate maze in that all cells are reachable and there is a unique simple path between any pairs of cells in the maze. Your goal is to write a program that reads the hexadecimal descriptions of a potential maze and tests to determine if it is legitimate. If there is a problem, your program must report only the first problem, as detailed below in the section titled "Output".

Input

The input consists of the descriptions of one or more candidate mazes. Each maze description will start with two integers, H and W, indicating the height and width of the maze, respectively, such that 1 ≤ H ≤ 50 and 2 ≤ W ≤ 50. Following this first line will be H rows of hexadecimal digits, with each row consisting of W digits. The input is terminated with a line displaying a pair of zeros.

Output

For each candidate maze, the program should output the first one of the following statements that applies: 
NO SOLUTION
UNREACHABLE CELL
MULTIPLE PATHS
MAZE OK
The classification statements are defined formally as follows:

NO SOLUTION - There is no path through the interior of the maze between the two exterior openings.

UNREACHABLE CELL - There is at least one cell in the maze that is not reachable by following passageways from either of the openings in the exterior walls of the maze.

MULTIPLE PATHS - There exists a pair of cells in the maze that have more than one simple path between them. Two simple paths are considered to be distinct if any part of the paths differ.

MAZE OK - None of the above problems exist.
Note well that for the second case given in the following examples, there is no path between the start and finish and there is an unreachable cell; the correct output should simply be NO SOLUTION, because that error message is listed first in the above list. Similarly, in the fourth example given, UNREACHABLE CELL is reported because that error has priority over the multiple paths.

Sample Input

6 7
9A8C98E
2E5753C
980A496
553C53C
53C75D5
3E3E363
3 3
F9A
D3E
3AC
1 8
3AAA8AAE
6 3
9AC
3C5
A24
9A6
5BC
3C7
5 4
8A8E
592C
5186
161C
3A63
5 4
8AAE
59AC
5386
1E1C
3A63
0 0

Sample Output

MAZE OK
NO SOLUTION
MAZE OK
UNREACHABLE CELL
MULTIPLE PATHS
MULTIPLE PATHS

HINT

Source

通过构图(用1表示墙,0表示通路),再转成dfs();

用一个father[]表示他的直接父结点,如果现在的点的直接父节点不是上一个父节点,那么vist[][]++;

如果,dfs()返回的值是false,表示没有路NO SOLUTION

如果,vist[][]>1表示有多路,MULTIPLE PATHS

如果最后有vist[][]==0,则说明有不能到达的点,则 UNREACHABLE CELL

都没有,则说明是:MAZE OK

转载请注明出处:寻找&星空の孩子

题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1566

#include<stdio.h>
#include<string.h>
#include<queue>
using namespace std;
const int N =;
struct node
{
int x,y;
};
int mmap[N][N],vist[N][N],father[N*N];
int mi,mj,x,y,l[];
void init(int num)
{
if(num>=&&num<=) l[]=;
else l[]=; if(num&) l[]=;
else l[]=; if(num<||num>&&num<) l[]=;
else l[]=; if(num==||num==||num==||num==||num==||num==||num==||num==) l[]=;
else l[]=;
}
void build()
{
if(mj>*y) mi+=,mj=;
mmap[mi][mj]=;
mmap[mi-][mj-]=mmap[mi-][mj+]=;
mmap[mi+][mj-]=mmap[mi+][mj+]=;
mmap[mi-][mj]|=l[];
mmap[mi][mj-]|=l[];
mmap[mi][mj+]|=l[];
mmap[mi+][mj]|=l[]; mj+=;
}
bool bfs()
{
node pre,now;
queue<node>q;
bool flag=false;
int dir[][]= {,,,-,,,-,};
memset(vist,,sizeof(vist));
for(int i=; i<x&&!flag; i++)
{
for(int j=; j<y&&!flag; j++)
{
if(i==||j==||i==x-||j==y-)
{
if(mmap[i][j]==)
{
memset(father,-,sizeof(father));//¸¸½áµã
now.x=i;
now.y=j;
q.push(now);
vist[i][j]=;
while(!q.empty())
{
pre=q.front();
q.pop();
for(int e=; e<; e++)
{
now.x=pre.x+dir[e][];
now.y=pre.y+dir[e][];
if(now.x>=&&now.x<x&&now.y>=&&now.y<y&&mmap[now.x][now.y]==)
{
if(vist[now.x][now.y]==)
{
vist[now.x][now.y]=;
father[now.x*y+now.y]=pre.x*y+pre.y;
if(now.x==||now.y==||now.x==x-||now.y==y-)
flag=;
q.push(now);
}
else if(father[pre.x*y+pre.y]!=now.x*y+now.y)
vist[now.x][now.y]++;
} }
} }
}
} }
return flag;
}
void print()
{
for(int i=; i<=x*; i++)
{
for(int j=; j<=y*; j++)
printf("%d ",mmap[i][j]);
printf("\n");
}
} int main()
{
char ch[];
while(scanf("%d%d",&x,&y),x+y)
{
mi=;
mj=;
memset(mmap,,sizeof(mmap));
for(int i=; i<x; i++)
{
scanf("%s",ch);
int tp;
for(int j=; j<strlen(ch); j++)
{
if(ch[j]>=''&&ch[j]<='')
tp=ch[j]-'';
else
tp=ch[j]-'A'+; init(tp);
build();
}
}
//print();
x=x*+;
y=y*+;
if(bfs())
{
int f[]= {};
for(int i=; i<x; i+=)
{
for(int j=; j<y; j+=)
{
if(vist[i][j]==)
f[]=;
else if(vist[i][j]>=)
f[]=;
}
}
if(f[])
{
printf("UNREACHABLE CELL\n");
continue;
}
if(f[])
{
printf("MULTIPLE PATHS\n");
continue;
}
printf("MAZE OK\n");
}
else printf("NO SOLUTION\n");
}
return ;
} /**************************************************************
Problem: 1566
User: aking2015
Language: C++
Result: Accepted
Time:44 ms
Memory:1200 kb
****************************************************************/

The Maze Makers(csu1566)的更多相关文章

  1. CodeForces 1292A NEKO's Maze Game(思维)

    #include <stdio.h> #include <string.h> #include <iostream> #include <string> ...

  2. canvas实例 ---- 制作简易迷宫(一)

    这个系列分为两部分,第一部分为迷宫的生成及操作,第二部分为自动寻路算法. 我们先看效果: See the Pen QGKBjm by fanyipin (@fanyipin) on CodePen. ...

  3. make基础(转)

    1. 基本规则 请点评 除了Hello World这种极简单的程序之外,一般的程序都是由多个源文件编译链接而成的,这些源文件的处理步骤通常用Makefile来管理.Makefile起什么作用呢?我们先 ...

  4. HDU 4044 GeoDefense(动态规划)

    GeoDefense Time Limit: 12000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tota ...

  5. 广度优先搜索(BFS)——迷宫的最短路径

    宽度优先搜索按照距开始状态由近到远的顺序进行搜索,因此可以很容易的用来求最短路径,最少操作之类问题的答案. 宽度优先搜索介绍(一篇不错的文章). 题目描述: 给定一个大小为N*M的迷宫.迷宫有通道和墙 ...

  6. HDU 3085 Nightmare Ⅱ(噩梦 Ⅱ)

    HDU 3085 Nightmare Ⅱ(噩梦 Ⅱ) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Ja ...

  7. 【转】强化学习(一)Deep Q-Network

    原文地址:https://www.hhyz.me/2018/08/05/2018-08-05-RL/ 1. 前言 虽然将深度学习和增强学习结合的想法在几年前就有人尝试,但真正成功的开端就是DeepMi ...

  8. 【强化学习】python 实现 q-learning 例五(GUI)

    本文作者:hhh5460 本文地址:https://www.cnblogs.com/hhh5460/p/10143579.html 感谢pengdali,本文的 class Maze 参考了他的博客, ...

  9. Delphi的程序单元、结构、基础知识(转)

    Object Passal的程序结构很特殊,与其它语言如C++,Object Windows等结构都不同.一个Delphi程序由多个称为单元的源代码模块组成.使用单元可以把一个大型程序分成多个逻辑相关 ...

随机推荐

  1. 7.AOP编程

    注解和xml混合使用 1.将所有的bean都配置xml中 <bean id="" class=""> 2.将所有的依赖都使用注解 @Autowire ...

  2. shell 文件操作

      序   在linux平台下开发,我们经常会接触到一些任务性质的工作,而处理方式多样化.现积累各个案例.   从远程服务器拉取文件到本地服务器   scp work@cp01-xx-dev.com: ...

  3. nginx 502 bad gateway 问题处理集锦

    一般看来, 这种情况可能是由于nginx默认的fastcgi进程响应的缓冲区太小造成的, 这将导致fastcgi进程被挂起, 如果你的fastcgi服务对这个挂起处理的不好, 那么最后就极有可能导致5 ...

  4. Visual Stuido快捷键

    转自:http://www.cnblogs.com/TankXiao/p/3164995.html 整理了一些VS的快捷键 格式化整个文档:(Ctrl + K, Ctrl + D)智能感知:(Ctrl ...

  5. Spring MVC 原理探秘 - 一个请求的旅行过程

    1.简介 在前面的文章中,我较为详细的分析了 Spring IOC 和 AOP 部分的源码,并写成了文章.为了让我的 Spring 源码分析系列文章更为丰富一些,所以从本篇文章开始,我将来向大家介绍一 ...

  6. mybatis环境配置与入门例子

    1.jar包的导入 mybatis需要jar包:mybatis-3.4.6.jar mysql驱动jar包:mysql-connector-java-5.1.34.-bin.jar 日志记录jar包: ...

  7. HoloLens开发手记 - 使用配件 Working with accessories

    HoloLens提供了通过蓝牙使用配件的能力.使用附件两种常见情况是用来点击手势和虚拟键盘.对本文来讲,两个最常见的配件就是HoloLens Clicker(点击器)和蓝牙键盘.HoloLens包含了 ...

  8. javascript 实现数据结构 - 队列

    队列是遵循FIFO(First In First Out,先进先出,也称为先来先服务)原则的一组有序的项.队列在尾部添加新元素,并从顶部移除元素.最新添加的元素必须排在队列的末尾. 1.构造函数构建队 ...

  9. Jenkins和gitlab集成自动构建

    Jenkins安装插件 Jenkins上需要安装如下插件 Gitlab Hook Plugin,GitLab Plugin Job配置 在需要自动触发的Job中 选择Build Triggers进行如 ...

  10. [HAOI2017] 新型城市化

    给出的图中恰包含2个团,则图的补图为一个二分图,其最大独立集为原图的最大团. 我们知道,二分图的最大独立集=V-最小顶点覆盖,最小顶点覆盖=最大匹配. 问题转化为:计算删去后最大匹配减小的边集. 所以 ...