普通的三维广搜,须要注意的是输入列,行,层

#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
#define M 11
using namespace std; int dir[6][3]={{0,1,0},{0,-1,0},{1,0,0},{-1,0,0},{0,0,1},{0,0,-1}};//6个方向
int vis[M][M][M];
char map[M][M][M];
int n,m,p,sx,sy,sz,ex,ey,ez; bool ck(int x,int y,int z)
{
if(x>=0&&x<n&&y>=0&&y<n&&z>=0&&z<n&&!vis[z][x][y]&&map[z][x][y]=='O')
return true;
return false;
}
struct node
{
int x,y,z,st;
}; void bfs( )
{
if(sx==ex&&sy==ey&&sz==ez){
cout<<n<<" "<<0<<endl;
return ;
}
memset(vis,0,sizeof vis);
queue<node> q;
node a,b;
a.z=sz,a.x=sx,a.y=sy,a.st=0;
vis[sz][sx][sy]=1;
q.push(a);
while(!q.empty()){
a=q.front(),q.pop();
for(int i=0;i<6;++i){
b.x=a.x+dir[i][0];
b.y=a.y+dir[i][1];
b.z=a.z+dir[i][2];
b.st=a.st+1;
if(!ck(b.x,b.y,b.z)) continue; if(b.x==ex&&b.y==ey&&b.z==ez){
cout<<n<<" "<<b.st<<endl;
return;
}
vis[b.z][b.x][b.y]=1;
q.push(b); }
}
printf("NO ROUTE\n");
return ; }
int main()
{
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
while(scanf("START %d",&n)!=EOF){
for(int i=0;i<n;++i){
for(int j=0;j<n;++j){
scanf("%s",map[i][j]);
}
} scanf("%d%d%d %d%d%d",&sy,&sx,&sz,&ey,&ex,&ez);
char str[10];
cin>>str;
getchar(); bfs( );
}
return 0;
}<span style="color:#3333ff;">
</span>





HDU 1240——Asteroids!(三维BFS)POJ 2225——Asteroids的更多相关文章

  1. hdu 1240 Asteroids! (三维bfs)

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

  2. HDU 1240 (简单三维广搜) Asteroids!

    给出一个三维的迷宫以及起点和终点,求能否到大终点,若果能输出最短步数 三维的问题无非就是变成了6个搜索方向 最后强调一下xyz的顺序,从输入数据来看,读入的顺序是map[z][x][y] 总之,这是很 ...

  3. hdu 1240(三维广搜)

    题意: 有一个n*n*n的三维空间. 给你起始坐标和终点坐标.要你从起点到终点,问最少需要多少步走出去.如果走不出去则输出"NO ROUTE". 空间中 'O' 表示这个点可以走, ...

  4. 三维BFS Poj 2251

    #include <iostream> #include <cstdio> #include <string> #include <cstring> # ...

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

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

  6. HDU 1240 Asteroids! 题解

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

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

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

  8. POJ 3041 Asteroids / UESTC 253 Asteroids(二分图最大匹配,最小点匹配)

    POJ 3041 Asteroids / UESTC 253 Asteroids(二分图最大匹配,最小点匹配) Description Bessie wants to navigate her spa ...

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

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

随机推荐

  1. stm32中断优先级

    VIC_IRQChannelPreemptionPriority:先占优先级  NVIC_IRQChannelSubPriority:从优先级 高先占优先级中断可以打断低先占优先级的中断,即可中断嵌套 ...

  2. IOS 调用系统相册或照相机tab按钮显示中文

  3. 探究绑定事件的this指向以及event传参的小问题

    this指向 直接上代码,凑合着看 <input type="button" onclick="page()" value="点我"& ...

  4. 大数据时代的 9 大Key-Value存储数据库

    在过去的十年中,计算世界已经改变.现在不仅在大公司,甚至一些小公司也积累了TB量级的数据.各种规模的组织开始有了处理大数据的需求,而目前关系型数据库在可缩放方面几乎已经达到极限. 一个解决方案是使用键 ...

  5. linux下shutdown无法关闭tomcat进程的解决方式

    1.问题 笔者在linux下发现使用tomcat6.0.41自带的./shutdown.sh常常无法停止进程,导致各种问题的发生,令笔者相当反感! 2.解决方式一: 查找到全部的tomcat进程 $ ...

  6. CF 319D(Have You Ever Heard About the Word?-模拟)

    D. Have You Ever Heard About the Word? time limit per test 6 seconds memory limit per test 256 megab ...

  7. poj 3266 Cow School 分数规划

    这个题目难度非常大,首先对于老师的一种方案,应用分数规划的一般做法,求出所有的c=t-rate*p,如果没有选择的c值中的最大值比选择了的c值中的最小值大,那么这个解是可以改进的. 那么问题就转化成了 ...

  8. hdu1370-Biorhythms

    http://acm.hdu.edu.cn/showproblem.php?pid=1370 中国剩余定理 已知(n+d)%23=a;   (n+d)%28=b;   (n+c)%33=i       ...

  9. string的不可变性

    1.不可变性 代码如下: static void Main(string[] args){string str1 = "a";string str2 = str1;str2 = & ...

  10. EasyUI - Datatable转Json and Json转Datatable

    using System; using System.Data; using System.Linq; using System.Collections; using System.Collectio ...