csu - 1566: The Maze Makers (bfs)
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)的更多相关文章
- The Maze Makers(csu1566)
1566: The Maze Makers Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 90 Solved: 33[Submit][Status][ ...
- Borg Maze(MST & bfs)
Borg Maze Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9220 Accepted: 3087 Descrip ...
- POJ 3026 : Borg Maze(BFS + Prim)
http://poj.org/problem?id=3026 Borg Maze Time Limit: 1000MS Memory Limit: 65536K Total Submissions ...
- POJ 3026 Borg Maze(bfs+最小生成树)
Borg Maze Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6634 Accepted: 2240 Descrip ...
- (POJ 3026) Borg Maze 最小生成树+bfs
题目链接:http://poj.org/problem?id=3026. Description The Borg is an immensely powerful race of enhanced ...
- Borg Maze(BFS+MST)
Borg Maze http://poj.org/problem?id=3026 Time Limit: 1000MS Memory Limit: 65536K Total Submissions ...
- 快速切题 poj 3026 Borg Maze 最小生成树+bfs prim算法 难度:0
Borg Maze Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8905 Accepted: 2969 Descrip ...
- POJ 3026 --Borg Maze(bfs,最小生成树,英语题意题,卡格式)
Borg Maze Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16625 Accepted: 5383 Descri ...
- POJ3026 Borg Maze(Prim)(BFS)
Borg Maze Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12729 Accepted: 4153 Descri ...
随机推荐
- OAuth2.0认证流程是如何实现的?
导读 大家也许都有过这样的体验,我们登录一些不是特别常用的软件或网站的时候可以使用QQ.微信或者微博等账号进行授权登陆.例如我们登陆豆瓣网的时候,如果不想单独注册豆瓣网账号的话,就可以选择用微博或者微 ...
- CF949B A Leapfrog in the Array
思路: 最终的时候,对于位置p,若p是奇数,则该位置的元素是(p + 1) / 2:若p是偶数,需要从p开始不断地迭代寻找上一次跳跃所处的位置(p = p + n - p / 2),直到p是奇数为止. ...
- GatewayWorker+Laravel demo
GatewayWorker 结合 Laravel 使用的简单案例,重点是在Laravel中使用GatewayClient发送消息 主要流程:GatewayWorker主要负责推送消息给客户端但不接受客 ...
- 聊5块钱P2V
上一秒还在写代码,下一秒就跑机房干活. 这台机器产制石器时代,重启一次后再就启动不了了.这个故障处理的方式我们以后再谈. 今天聊聊啥是P2V,国人总喜欢弄些稀奇古怪的定义来证明自己技术很牛X,就跟当年 ...
- Python __str__(self)和__unicode__(self)
object.__str__(self) Called by the str() built-in function and by the print statement to compute the ...
- 用idea+maven编译打包spark project core错误:java.lang.RuntimeException: Unable to load a Suite class
Discovery starting. *** RUN ABORTED *** java.lang.RuntimeException: Unable to load a Suite class tha ...
- R in action 读书笔记(1)--第五章:高级数据管理
5.2.1数学函数 函数 描述 abs(x) 绝对值 sqrt(x) 平方根 ceiling(x) 不小于x的最小整数 floor(x) 不大于x的最大整数 trunc(x) 向0的方向截取的X中的整 ...
- SQL——视图、事务、锁、存储过程
https://www.bilibili.com/video/av15496406/?p=57 https://blog.csdn.net/u013630349/article/details/750 ...
- 数组,寻找第K大的数
时间复杂度 O(n) def partition(data,left,right): if (len(data)<=0 or left<0 or right>=len(data)): ...
- Mac OS 使用asio库
下载地址:http://sourceforge.net/projects/asio/files/asio/1.12.2%20%28Stable%29/ 本人下载的版本:asio-1.12.2 1,本人 ...