# Asteroids!_poj2225

0
10

#include <iostream>
#include <string>
#include <queue>
#include <cstdio>
using namespace std;
bool mapp[10][10][10];
int a,b,c,d,e,f,n;
int dir[6][3]={{0,0,1},{0,1,0},{0,0,-1},{0,-1,0},{1,0,0},{-1,0,0}};
struct point{
int x,y,z,step;
point(int xx,int yy,int zz,int ss=0):x(xx),y(yy),z(zz),step(ss){}
point(){}
};
bool judge(point ipo){//区分或与与
if(ipo.x>=n||ipo.x<0)return 0;
if(ipo.y>=n||ipo.y<0)return 0;
if(ipo.z>=n||ipo.z<0)return 0;
if(mapp[ipo.z][ipo.y][ipo.x]==1)return 0;
return 1;
}
int bfs(){
queue<point>que;
que.push(point(a,b,c));
point now;
int tstep;
while(!que.empty()){
now=que.front();
que.pop();
if(now.x==d&&now.y==e&&now.z==f){
return now.step;
}
//if(judge(now)){mapp[now.z][now.y][now.x]=1; }
mapp[now.z][now.y][now.x]=1;
int tx,ty,tz;
tstep=now.step+1;
for(int t=0;t<6;t++){
tx=now.x+dir[t][2];
ty=now.y+dir[t][1];
tz=now.z+dir[t][0];
if(judge(point(tx,ty,tz)))que.push(point(tx,ty,tz,tstep));//判断次数相等，插入删除次数少
}
}
return -1;
}
int main()
{
string str;
int i,j,k;
char ch;
while(cin >> str >> n){
for(i=0;i<n;i++)
for(j=0;j<n;j++)
for(k=0;k<n;k++)
mapp[i][j][k]=0;
getchar();
for(i=0;i<n;i++){
for(j=0;j<n;j++){
for(k=0;k<n;k++){
ch=getchar();
if(ch==’X’)mapp[i][j][k]=1;
}
getchar();
}
}
scanf(“%d%d%d”,&a,&b,&c);
scanf(“%d%d%d”,&d,&e,&f);
int ans=bfs();
cin >> str;
if(ans==-1)cout << “NO ROUTE” << endl;
else cout << n << ‘ ‘ << ans << endl;
}
return 0;
}
//对应关系
//x y z
//k j i
//a b c
//d e f

<

0