1 #include<iostream>
2 #include<cstdio>
3 #include<cstdlib>
4 #include<queue>
5 #include<cmath>
6 #include<cstring>
7
8 using namespace std;
9
10 int dx[] = {1,-1, 0, 0, 0, 0};//三维坐标,六个方向,每次只是其中一个坐标变 化,而保持另外两个不变。
11 int dy[] = {0, 0, 1,-1, 0, 0};
12 int dz[] = {0, 0, 0, 0, 1,-1};
13 int n;
14 char map[11][11][11], s[10];
15 int visit[11][11][11];
16
17 typedef struct
18 {
19 int row, col;
20 int slice, step;
21 }Site;
22 queue<Site>q;
23
24 int Equal(Site S1, Site S2)//判断两个位置是否相等,若相等则到达
25 {
26 if(S1.col==S2.col&&S1.row==S2.row&&S1.slice==S2.slice)
27 return 1;
28 return 0;
29 }
30 int True(Site S)//判断位置是否在图当中
31 {
32 if(S.row>=0&&S.row<n&&S.col>=0&&S.col<n&&S.slice>=0&&S.slice<n)
33 return 1;
34 return 0;
35 }
36
37 int main()
38 {
39
40 int i, j, k, flag;
41 Site Start, Target;
42
43 while(scanf("%s%d", s, &n) != EOF)
44 {
45 for(i=0; i<n; i++)
46 for(j=0; j<n; j++)
47 {
48 scanf("%s", map[i][j]);
49 }
50 scanf("%d%d%d",&Start.col, &Start.row, &Start.slice);
51 scanf("%d%d%d",&Target.col, &Target.row, &Target.slice);
52 scanf("%s", s);
53 memset(visit, 0, sizeof(visit));
54 visit[Start.slice][Start.row][Start.col] = 1;
55 Start.step = 0;
56 q.push(Start);
57 flag = 0;
58 while(!q.empty())
59 {
60 Site u = q.front();
61 q.pop();
62 if(Equal(u,Target))
63 {
64 flag = 1;
65 printf("%d %d\n", n, u.step);
66 break;
67 }
68 for(i=0; i<6; i++)
69 {
70 Site V;
71 V.slice = u.slice + dx[i];
72 V.row = u.row + dy[i];
73 V.col = u.col + dz[i];
74 V.step = u.step + 1;
75 if(!visit[V.slice][V.row][V.col]&&True(V)&&map[V.slice][V.row][V.col]!='X')
76 {
77 q.push(V);
78 visit[V.slice][V.row][V.col] = 1;
79 }
80 }
81 }
82 if( !flag )
83 printf("NO ROUTE\n");
84 while(!q.empty())
85 {
86 q.pop();
87 }
88 }
89 return 0;
90 }
91