题目:​​http://acm.hdu.edu.cn/showproblem.php?pid=1240​

题目解析:题目给了一个三维的空间坐标系,找一个点到另一个的最短的距离,这其实和二维的一样,

只不过有些的小小的改动,我自己是按照广搜的,每一次搜完之后清空

#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>
const int MAX=1000000;
using namespace std;
typedef struct point
{
int x,y,z;
int step;
};
char space[13][13][13];
int dri[6][3]={{0,0,1},{0,0,-1},{1,0,0},{-1,0,0},{0,1,0},{0,-1,0}};
queue<point> q;
int A,B,C,D,E,F;
int N;
int summin[13][13][13];
int BFS()
{
int aa,bb,cc,i;
point hd;
hd.x=A,hd.y=B,hd.z=C;
hd.step=0;
q.push(hd);
while(!q.empty())
{
point tmp;
tmp=q.front();
//cout<<tmp.x<<tmp.y<<tmp.z<<endl;
q.pop();
for(i=0;i<6;i++)
{
aa=tmp.x+dri[i][0],bb=tmp.y+dri[i][1],cc=tmp.z+dri[i][2];
if(aa>=0&&aa<N&&bb>=0&&bb<N&&cc>=0&&cc<N&&space[aa][bb][cc]=='O')
{
point t;
t.x=aa;
t.y=bb;
t.z=cc;
t.step=tmp.step+1;
if(t.step<summin[aa][bb][cc])
{
q.push(t);
summin[aa][bb][cc]=t.step;
}
}
}
}
return summin[D][E][F];
}
int main()
{
char a[6],b[4];
int i,j,k,temp;
while(scanf("%s%d",a,&N)!=EOF)
{
for(i=0;i<N;i++)
for(j=0;j<N;j++)
for(k=0;k<N;k++)
{
scanf(" %c",&space[k][j][i]);
summin[k][j][i]=MAX;
}
cin>>A>>B>>C>>D>>E>>F;
scanf("%s",b);
if(A==D&&B==E&&C==F)
{
printf("%d %d\n",N,0);
continue;
}
temp=BFS();
if(temp==MAX)
printf("%s\n","NO ROUTE");
else
printf("%d %d\n",N,temp);
while(!q.empty())
q.pop();
}
return 0;
}