Asteroids
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <queue>
using namespace std;
char board[20][20][20];
int vis[20][20][20];
int n;
int sx,sy,sz;
int ex,ey,ez;
int tx[6] = {1,-1,0,0,0,0};
int ty[6] = {0,0,1,-1,0,0};
int tz[6] = {0,0,0,0,1,-1};
struct node {
int x, y, z, step;
};
int in(int x, int y, int z) {
if(x >= 0 && y >= 0 && z >= 0 && x < n && y < n && z < n )
return 1;
return 0;
}
int bfs(int sx, int sy, int sz) {
if(sx == ex && sy == ey && sz == ez) {
return 0;
}
queue<node> Q;
node temp;
temp.x = sx;
temp.y = sy;
temp.z = sz;
temp.step = 0;
vis[sx][sy][sz] = 1;
Q.push(temp);
while( !Q.empty() ) {
node p = Q.front();
Q.pop();
if(p.x == ex && p.y == ey && p.z == ez )
return p.step;
for(int i = 0; i < 6; i++) {
int xx = p.x + tx[i];
int yy = p.y + ty[i];
int zz = p.z + tz[i];
if(in(xx, yy, zz) && board[xx][yy][zz] != 'X' && !vis[xx][yy][zz]) {
node next;
vis[xx][yy][zz] = 1;
next.x = xx;
next.y = yy;
next.z = zz;
next.step = p.step + 1;
Q.push(next);
}
}
}
return -1;
}
int main() {
//freopen("data.in", "r", stdin);
string s;
int i,j,k;
while(cin >> s >> n) {
//cout << s << n << endl;
memset(board, '#', sizeof(board));
memset(vis, 0, sizeof(0));
//输入的N*N*N的图,最慢增长的应该是 z轴的数字。
//所以Z轴的应该用i来代替读入,因为三重循环的时候i,j,k中i是增长最慢的。
for(i = 0; i<n; i++)
for(j = 0; j<n; j++)
for(k = 0; k<n; k++)
cin >> board[j][k][i];//尼玛,坑爹的地方,考察数据的输入,你妹有意思吗
cin >> sx >> sy >> sz;
cin >> ex >> ey >> ez;
cin >> s;
int ans = bfs(sx, sy, sz);
if(ans >= 0)
printf("%d %d\n", n, ans);
else
printf("NO ROUTE\n");
}
return 0;
}