题目链接:http://poj.org/problem?id=2225

这里要注意的是,输入的是坐标x,y,z,那么这个点就是在y行,x列,z层上。

我竟然WA在了结束搜索上了,写成了输出s.step.我要调疯了。

#include <stdio.h>
#include <queue>
#include <string.h> using namespace std; struct Point
{
int x,y,z;
int step;
} points[]; char maps[][][];
bool vis[][][]; ///上下前后左右
int to[][]= {{,,},{-,,},{,,},{,-,},{,,-},{,,}}; int main()
{
char str[];
while(scanf("%s",str)!=EOF)
{
memset(vis,false,sizeof(vis)); int n;
scanf("%d",&n);
for(int i=; i<n; i++)
for(int j=; j<n; j++)
scanf("%s",maps[i][j]); int x1,y1,z1; ///x 行,y列,z层
int x2,y2,z2;
scanf("%d%d%d%d%d%d",&y1,&x1,&z1,&y2,&x2,&z2); char tmp[];
scanf("%s",tmp); queue<Point> Q;
Point s,next;
s.x = x1;
s.y = y1;
s.z = z1;
s.step = ;
Q.push(s);
vis[s.z][s.x][s.y] = true;
int ans = ;
bool flag = false; while(!Q.empty())
{
Point f;
f = Q.front();
Q.pop();
if(f.x==x2&&f.y==y2&&f.z==z2)
{
flag = true;
ans = f.step;
break;
}
for(int i=; i<; i++)
{
next.x = f.x + to[i][];
next.y = f.y + to[i][];
next.z = f.z + to[i][]; if(next.x<||next.x>=n||next.y<||next.y>=n||next.z<||next.z>=n)
continue;
if(vis[next.z][next.x][next.y]||maps[next.z][next.x][next.y]=='X')
continue; next.step = f.step + ;
//printf("%d %d %d ",next.x,next.y,next.z);
//printf("%d\n",next.step);
vis[next.z][next.x][next.y] = true;
Q.push(next);
}
}
if(flag)
printf("%d %d\n",n,ans);
else printf("NO ROUTE\n");
}
return ;
}

Poj(2225),三维BFS的更多相关文章

  1. POJ 2251 三维BFS(基础题)

    Dungeon Master Description You are trapped in a 3D dungeon and need to find the quickest way out! Th ...

  2. POJ 2251 Dungeon Master --- 三维BFS(用BFS求最短路)

    POJ 2251 题目大意: 给出一三维空间的地牢,要求求出由字符'S'到字符'E'的最短路径,移动方向可以是上,下,左,右,前,后,六个方向,每移动一次就耗费一分钟,要求输出最快的走出时间.不同L层 ...

  3. POJ 2049— Finding Nemo(三维BFS)10/200

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/u013497151/article/details/29562915 海底总动员.... 这个题開始 ...

  4. POJ.2251 Dungeon Master (三维BFS)

    POJ.2251 Dungeon Master (三维BFS) 题意分析 你被困在一个3D地牢中且继续寻找最短路径逃生.地牢由立方体单位构成,立方体中不定会充满岩石.向上下前后左右移动一个单位需要一分 ...

  5. hdu 1240:Asteroids!(三维BFS搜索)

    Asteroids! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  6. AOJ.866 飞越原野 (三维BFS)

    AOJ.866 飞越原野 (三维BFS) 题意分析 点我挑战题目 相比于普通的BFS,要多一维来记录当前剩余的体力.而且还要额外的一层循环来处理,飞过的路程. 代码总览 #include <io ...

  7. SDUT OJ 1124 飞越原野 (三维BFS练习)

    飞跃原野 nid=24#time" title="C.C++.go.haskell.lua.pascal Time Limit5000ms Memory Limit 65536K ...

  8. HDU 1240——Asteroids!(三维BFS)POJ 2225——Asteroids

    普通的三维广搜,须要注意的是输入:列,行,层 #include<iostream> #include<cstdio> #include<cstring> #incl ...

  9. POJ 2251 Dungeon Master (三维BFS)

    题目链接:http://poj.org/problem?id=2251 Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total S ...

随机推荐

  1. jinkens 'python' 不是内部或外部命令,也不是可运行的程序 或批处理文件。

    jinkens执行构建时报错 解决方法,就是指定路径.python的安装目录和被执行文件的的目录

  2. php数组·的方法-数组检索

    /* * //数组检索函数 * */ //array_keys() 获取数组中所有键名 //array_values() 获取数组中所有键名 $arr6=range('a','e'); print_r ...

  3. RobotFramework AppiumLibrary 用户关键字

    RobotFramework AppiumLibrary 用户关键字 最近在用robotframework搞安卓app 的自动化,其中用到了 AppiumLlibrary 的关键字,我都映射成了用户关 ...

  4. TCP/IP协议<二>

    一.TCP/IP的标准化 1.TCP/IP的含义 一般来说,TCP/IP是利用IP进行通信时所必须用到的协议群的统称. 具体点,IP或ICMP.TCP或UDP.TELENT或FTP.以及HTTP等都属 ...

  5. Unity 在Inspector面板,脚本前面的激活对勾

    写个脚本,把它挂在一个游戏对象上: using System.Collections; using System.Collections.Generic; using UnityEngine; pub ...

  6. 用Java 8 Lambda表达式实现设计模式:命令模式

    在这篇博客里,我将说明如何在使用 Java 8 Lambda表达式 的函数式编程方式 时实现 命令 设计模式 .命令模式的目标是将请求封装成一个对象,从对客户端的不同类型请求,例如队列或日志请求参数化 ...

  7. FileZila

    FileZilla下载文件失败的原因 对应访问的目录在服务器上没有权限下载 在本地没有切换到用户的家目录

  8. LCS与打印路径

    /* LCS */ #include<bits/stdc++.h> using namespace std; const int maxn = 1000; int dp[maxn][max ...

  9. redis 读写锁实现

    一 先搞清楚读写锁要做什么. 基本就是 读读不互斥,读写互斥,写写互斥.可重入. 关于redis读写锁,我写了一次之后,总觉得很怪,然后就上网看到大神的redisson了,果断借鉴一番. 二 读行为 ...

  10. Unable to run man pages on Centos 6

    I just installed CentOS 6 with minimal install. When i tried to read the linux manual pages using ma ...