天啦一道超水的题居然被我看错输入顺序WA到现在,差点连死的心都有了。。。
总之A了就好,A了就好,A了就好。。。。
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <queue>
#include <stdlib.h>
using namespace std;
const int N = 30;
const int INF = 1000000;
char Map[N][N][N];
int visit[N][N][N];
int n;
struct Poi
{
int x, y, z;
int t;
};
int dir[6][3] = {{1, 0, 0}, {-1, 0, 0}, {0, 0, 1}, {0, 0, -1}, {0, 1, 0}, {0, -1, 0}};
int go(int x0, int y0, int z0)
{
if(x0 >= 0 && x0 < n && y0 >= 0 && y0 < n && z0 >= 0 && z0 < n && Map[x0][y0][z0] == 'O') return 1;
else return 0;
}
int BFS(int stx, int sty, int stz, int edx, int edy, int edz)
{
Poi st, ed;
queue <Poi> q;
st.x = stx;
st.y = sty;
st.z = stz;
st.t = 0;
q.push(st);
memset(visit, 0, sizeof(visit));
visit[stx][sty][stz] = 1;
while(!q.empty())
{
st = q.front();
q.pop();
if(st.x == edx && st.y == edy && st.z == edz) return st.t;
for(int i = 0; i < 6; i ++)
{
ed.x = st.x + dir[i][0];
ed.y = st.y + dir[i][1];
ed.z = st.z + dir[i][2];
if(go(ed.x, ed.y, ed.z) && !visit[ed.x][ed.y][ed.z])
{
visit[ed.x][ed.y][ed.z] = 1;
ed.t = st.t + 1;
q.push(ed);
}
}
}
return -1;
}
int main()
{
// freopen("in.txt", "r", stdin);
int i, j, ans, stx, sty, stz, edx, edy, edz;
char s[20];
while(~scanf("%s %d", s, &n))
{
for(i = 0; i < n; i ++)
for(j = 0; j < n; j ++)
scanf("%s", Map[i][j]);
scanf("%d%d%d%d%d%d", &stz, &sty, &stx, &edz, &edy, &edx);
scanf("%s", s);
ans = BFS(stx, sty, stz, edx, edy, edz);
if(ans == -1) printf("NO ROUTE\n");
else printf("%d %d\n", n, ans);
}
return 0;
}