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. web+ admin template,spa管理应用后台,easyui后台正式发布

    演示地址:http://admintemplate.webplus.org.cn/ v1.0 (2016/7/27) 扁平化风格 全屏支持 后台管理不使用iframe,全ajax开发 权限管理 商品管 ...

  2. 教你如何在实战项目中使用WCF

    我们都知道调用WCF直接在Service References中引用可以远程调用的WCF Url就行了. 但是我们想过没,在Development环境中可以这样做,但是QA.UAT.Productio ...

  3. ssm基础配置

    1.导包 <dependencies> <dependency> <groupId>org.springframework</groupId> < ...

  4. POI导出时,将指定的列设置为下拉列表

    本示例设置第2列为下拉框(下拉框内容为:是/否),从第5行开始到5657行结束. 关键代码示例: ComboxList = new String[]{"是","否&quo ...

  5. spring framework 第一章数据库管理(data access)

    spring data access 的网址:https://docs.spring.io/spring/docs/current/spring-framework-reference/index.h ...

  6. web 自动化测试 selenium基础到应用(目录)

    第一章   自动化测试前提及整体介绍 1-1功能测试和自动化测试的区别 1-2自动化测试流程有哪些 1-3自动化测试用例和手工用例的区别 1-4 自动化测试用例编写 1-5 selenium的优势以及 ...

  7. vue HTTP请求(针对vue-resource)

    //初始化页面需要做什么事情 //点击后需要做什么事情 //鼠标.键盘.冒泡.默认行为等事件 //前端调用接口就是按需展示数据//created和mounted里面都可以做数据处理,唯一不同的是cre ...

  8. (转)淘淘商城系列——VMware添加已配置好的虚拟机

    http://blog.csdn.net/yerenyuan_pku/article/details/72802323 我们有时候会碰到虚拟机环境搭建特别麻烦,很容易出错的问题,而这时我们又刚好有别人 ...

  9. (转)淘淘商城系列——maven工程debug调试

    http://blog.csdn.net/yerenyuan_pku/article/details/72784074 上文我们已经实现了商品列表展示的功能,在实际开发中我们肯定是要经常对maven工 ...

  10. 【原】简单shell练习(二)

    1.查找awk # cat /etc/passwd |awk -F ':' 'BEGIN {print "name,shell"} {print $1","$7 ...