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 ...
随机推荐
- .net 发送邮件验证码
using System;using System.Collections.Generic;using System.Linq;using System.Net;using System.Net.Ma ...
- jQueryUI 购物车拖放功能
<style type="text/css"> .basket{ border:transparent solid 2px; } img{ width:80px; he ...
- 使用一个CSS Class去给标签定义Style
使用一个CSS Class去给标签定义Style 类是可重用的样式,可以添加到HTML元素. 下面是一个CSS类声明的例子: <style> .blue-text { colo ...
- CCF|最小差值|Java
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = ...
- 解决jquery与其他库的冲突
1.jquery在其他库之后导入 第一种: jQuery.noConflict();//将变量$的控制权限交给其他类库,即将$的控制权让渡给其他类库 jQuery(function(){ jQuery ...
- sql发送邮件- html 格式
ALTER PROCEDURE dbo.sx_pro_AutoEmailContent AS Begin declare @Rqty int declare @n int declare @m_rec ...
- Ghost Win10系统X64位和32位10041装机版下载
更多系统下载尽在系统妈:http://www.xitongma.com 特别说明: 1.C:盘分区须至少15GB(安装过程有大量的解压临时文件),安装完成后C:盘占用10GB左右! 2.安装之后如有硬 ...
- 恩智浦Freescale Cortex-A9 迅为IMX6开发板平台初体验
iTOP-i.MX6 开发板预装 Android4.4 系统,采用 9.7 寸(或者 7 寸或者 4.3 寸)IPS 屏 幕,至少 5 点以上触控,操作流畅,无论是高清视频.游戏等都会有上佳的表现,实 ...
- inux 软件编译、安装、删除
640?wx_fmt=otherimage.png 本文学习内容 手动安装软件 手动安装下载源码的软件 源码编译3步骤 deb包-包依赖管理 dekg -l 查看所以安装deb的包 apt-get仓库 ...
- CSS3 自动旋转
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...