http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1566

题意还是蛮难懂的,至少对于我来说,需要认真读题。

输入矩阵的每一个数字换成2进制后,顺时针围一圈,用1表示墙,0表示空,这样就可以表示出一个迷宫,现在就是判断这个迷宫属于4种类型中哪种类型。

参考了 大神博客。构图很难,并且想法跟以往的题都不一样。是一个好题。

 #include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <string>
#include <set>
#include <functional>
#include <numeric>
#include <sstream>
#include <stack>
#include <map>
#include <queue>
#pragma comment(linker, "/STACK:102400000,102400000")
#define CL(arr, val) memset(arr, val, sizeof(arr)) #define ll long long
#define inf 0x7f7f7f7f
#define lc l,m,rt<<1
#define rc m + 1,r,rt<<1|1
#define pi acos(-1.0) #define L(x) (x) << 1
#define R(x) (x) << 1 | 1
#define MID(l, r) (l + r) >> 1
#define Min(x, y) (x) < (y) ? (x) : (y)
#define Max(x, y) (x) < (y) ? (y) : (x)
#define E(x) (1 << (x))
#define iabs(x) (x) < 0 ? -(x) : (x)
#define OUT(x) printf("%I64d\n", x)
#define lowbit(x) (x)&(-x)
#define Read() freopen("a.txt", "r", stdin)
#define Write() freopen("b.txt", "w", stdout);
#define maxn 1000000000
#define N 2510
#define mod 1000000000
using namespace std; int n,m;
int num[][],vis[][];
int dir[][]={,,,-,,,,,,,-,};
//这里必须要对应 是为了防止往回走
struct point
{
int a,b;
};
int main()
{
//freopen("a.txt","r",stdin);
char s[];
int x,y,nx,ny;
while(~scanf("%d%d",&n,&m))
{
if(!n&&!m) break;
for(int i=;i<=n;i++)
{
scanf("%s",s+);
for(int j=;j<=m;j++)
{
if(s[j]>=''&&s[j]<='') num[i][j]=s[j]-'';
else num[i][j]=s[j]-'A'+;
num[i][j]=~num[i][j]; //读入之后 按位取反 ,能走的变成1 不能走的变成0
}
}
x=; //找出 起点和终点
for(int i=;i<=n;i++) //第一列或者第m列 看左右边界
{
if(num[i][]&) //代表表示 num[i][1]的四位2进制数中最后一位是1 代表有缺口
{
if(!x) x=i,y=;
else nx=i,ny=;
}
if(num[i][m]&)
{
if(!x) x=i,y=m;
else nx=i,ny=m;
}
}
for(int i=;i<=m;i++) //同上,看上下边界
{
if(num[][i]&)
{
if(!x) x=,y=i;
else nx=,ny=i;
}
if(num[n][i]&)
{
if(!x) x=n,y=i;
else nx=n,ny=i;
}
}
// printf("%d %d %d %d\n",x,y,nx,ny);
memset(vis,,sizeof(vis));
int mul=;
queue<point>que;
point now,next;
now.a=x,now.b=y;
vis[now.a][now.b]=;
que.push(now);
while(!que.empty()) //扩展所有能到达的点
{
next=que.front();que.pop();
for(int i=;i<;i++)
{
if(vis[next.a][next.b]==dir[i][]) continue; //已经访问过,防止往回走,
if(num[next.a][next.b]&dir[i][]) //该方向能访问
{
now.a=next.a+dir[i][];
now.b=next.b+dir[i][];
if(now.a>=&&now.a<=n&&now.b>=&&now.b<=m)
{
if(vis[now.a][now.b]) mul=; //多次到达同一个点
else
{
if(dir[i][]==) vis[now.a][now.b]=; //赋值相反方向的值给vis,防止往回走,跟上面的判断对应
else if(dir[i][]==) vis[now.a][now.b]=;
else if(dir[i][]==) vis[now.a][now.b]=;
else if(dir[i][]==) vis[now.a][now.b]=;
que.push(now);
}
}
}
}
}
if(vis[nx][ny]) //能到出口
{
bool flag=;
for(int i=;i<=n;i++)
{
for(int j=;j<=m;j++)
if(!vis[i][j])
{
//printf("%d %d\n",i,j);
flag=;
break;
}
if(flag) break;
}
if(flag) printf("UNREACHABLE CELL\n"); //有点不能到达
else
{
if(mul) printf("MULTIPLE PATHS\n"); //多次到达
else printf("MAZE OK\n"); //只有一条路径
}
}
else printf("NO SOLUTION\n"); //没有路径
}
return ;
}

csu - 1566: The Maze Makers (bfs)的更多相关文章

  1. The Maze Makers(csu1566)

    1566: The Maze Makers Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 90  Solved: 33[Submit][Status][ ...

  2. Borg Maze(MST & bfs)

    Borg Maze Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9220   Accepted: 3087 Descrip ...

  3. POJ 3026 : Borg Maze(BFS + Prim)

    http://poj.org/problem?id=3026 Borg Maze Time Limit: 1000MS   Memory Limit: 65536K Total Submissions ...

  4. POJ 3026 Borg Maze(bfs+最小生成树)

    Borg Maze Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6634   Accepted: 2240 Descrip ...

  5. (POJ 3026) Borg Maze 最小生成树+bfs

    题目链接:http://poj.org/problem?id=3026. Description The Borg is an immensely powerful race of enhanced ...

  6. Borg Maze(BFS+MST)

    Borg Maze http://poj.org/problem?id=3026 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions ...

  7. 快速切题 poj 3026 Borg Maze 最小生成树+bfs prim算法 难度:0

    Borg Maze Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8905   Accepted: 2969 Descrip ...

  8. POJ 3026 --Borg Maze(bfs,最小生成树,英语题意题,卡格式)

    Borg Maze Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16625   Accepted: 5383 Descri ...

  9. POJ3026 Borg Maze(Prim)(BFS)

    Borg Maze Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12729   Accepted: 4153 Descri ...

随机推荐

  1. ASP.NET MVC+Bootstrap个人博客之修复UEditor编辑时Bug(四)

    我的个人博客站在使用百度富文本编辑器UEditor修改文章时,遇到了一些问题,(不知是bug,还是我没有配置好).但总算找到了解决方法,在此记录下来. 遇到的问题: 正常来讲,进入文章修改页,只需将U ...

  2. 快速体验openstack-用devstack安装openstack

    官网安装说明: --2014年11月15日14:14:21 安装环境:Ubuntu12.04,安装官网的说明遇到了小问题,记录在这里 --http://docs.openstack.org/devel ...

  3. taskctl的后台字符界面登录不了解决办法

    今天在使用taskctl的designer时,十多分钟挂了2次,每次挂了之后就签不出来了,只能等半小时,然后在taskctl的QQ群里咨询了,给的解决方案是 http://www.taskctl.co ...

  4. 【译】x86程序员手册41-10.6 TLB(快表)测试

    译注:本章基本未做翻译 10.6 TLB Testing TLB测试 The 80386 provides a mechanism for testing the Translation Lookas ...

  5. vue-cropper

    项目中用到了vue-cropper插件,让我觉得很好用附上两个地址 vue-cropper在git上的地址 https://github.com/xyxiao001/vue-cropper 针对vue ...

  6. 处理不同jQuery版本的兼容性问题

    众所周知,jquery版本很多,而且有些版本的冲突也非常明显,有一些网上流传的很实用的插件是用A版本写的,但是要实现另各功能又必須用B版本.所以实现版本之間的和平相处很重要. 1.这里介绍一个函数,可 ...

  7. jquery 点击切换div

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  8. chgrp - 改变文件的组所有权

    总览 chgrp [选项] 组文件... POSIX 选项: [-R] [--] Austin 草拟选项: [-hHLPR] GNU 团体指示: [--reference=rfile] GNU 选项 ...

  9. 使用Caliburn.Micro系列2:Convention

    CM中实现一个比较有意思的特性,就是智能匹配. 通常使用MVVM的写法:在匹配 View和ViewModel时会使用DataContext,在匹配数据属性时使用Binding,在匹配事件命令时使用Co ...

  10. Delphi最简化异步选择TCP服务器

    网上Delphi的Socket服务器优良代码,实在少见,索性写个简化的异步Socket服务器,虽然代码较少,但却该有的都有了,使用的是异步选择WSAAsyncSelect,减少了编写线程的繁琐.可能会 ...