You are in space now, but you want to go back to Earth, there are many planets in the stars, and all you have to do is to avoid these planets.
Given the planetary distribution chart in a three-dimensional space, X represents the planetary area, and the uppercase letter O represents the blank area. Next is your starting point coordinate and target coordinate.
You need to determine whether the destination can be reached. If you can, you need to output N and the smallest number of steps; otherwise, no route is output.
It should be noted that the input distribution chart is then widely searched and OK. At the beginning, I got stuck because of a mistake in input. Just open a three-digit array.
Asteroids!
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission (s): 2663 Accepted Submission (s): 1793
Problem Description
You're in space.
You want to get home.
There are asteroids.
You don't have want to hit them.
Input
Input to this problem will consist of a (non-empty) series of up to 100 data sets. each data set will be formatted according to the following description, and there will be no blank lines separating data sets.
A single data set has 5 components:
Start line-A single line, "start n", where 1 <= N <= 10.
Slice list-A series of N slices. Each slice is an N x N matrix representing a horizontal slice through the asteroid field. Each position in the matrix will be one of two values:
'O'-(the letter "oh") Empty space
'X'-(upper-case) Asteroid present
Starting Position-A single line, "a B c", denoting the <A, B, C> coordinates of your craft's starting position. the coordinate values will be integers separated by individual spaces.
Target Position-A single line, "d e f", denoting the <D, E, F> coordinates of your target's position. the coordinate values will be integers separated by individual spaces.
End line-A single line, "END"
The origin of the coordinate system is <, 0>. Therefore, each component of each coordinate vector will be an integer between 0 and N-1, fully passive.
The first coordinate in a set indicates the column. Left column = 0.
The second coordinate in a set indicates the row. Top row = 0.
The third coordinate in a set indicates the slice. First slice = 0.
Both the Starting Position and the Target Position will be in empty space.
Output
For each data set, there will be exactly one output set, and there will be no blank lines separating output sets.
A single output set consists of a single line. if a route exists, the line will be in the format "x y ", where X is the same as N from the corresponding input data set and Y is the least number of moves necessary to get your ship from the starting position to the target position. if there is no route from the starting position to the target position, the line will be "no route" instead.
A move can only be in one of the six basic directions: up, down, left, right, forward, back. phrased more precisely, a move will either increment or decrement a single component of your current position vector by 1.
Sample Input
START 1
O
0 0 0
0 0 0
END
START 3
XXX
XXX
XXX
OOO
OOO
OOO
XXX
XXX
XXX
0 0 1
2 2 1
END
START 5
OOOOO
OOOOO
OOOOO
OOOOO
OOOOO
OOOOO
OOOOO
OOOOO
OOOOO
OOOOO
XXXXX
XXXXX
XXXXX
XXXXX
XXXXX
OOOOO
OOOOO
OOOOO
OOOOO
OOOOO
OOOOO
OOOOO
OOOOO
OOOOO
OOOOO
0 0 0
4 4 4
END
Sample Output
1 0
3 4
NO ROUTE
#include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> using namespace std; struct nobe { int x,y,z,time; }q[3000]; char map[10][10][10]; int visit[10][10][10],n,m,l,t,k; int go[6][3]={0,0,1,0,0,-1,0,1,0,0,-1,0,1,0,0,-1,0,0},d[3000],flag; void BFS(int a,int b,int c) { struct nobe que,ue; int front=0,rear=0; int nx,ny,nz,i; que.x=a; que.y=b; que.z=c; que.time=0; q[rear++]=que; while(front<rear) { ue=q[front++]; if(ue.x==n&&ue.y==m&&ue.z==l) { flag=1; return ; } for(i=0;i<6;i++) { nx=ue.x+go[i][0]; ny=ue.y+go[i][1]; nz=ue.z+go[i][2]; if(!visit[nz][nx][ny]&&map[nz][nx][ny]=='O'&&nx>=0&&nx<=n&&ny>=0&&ny<=m&&nz>=0&&nz<=l) { visit[nz][nx][ny]=1; que.time=nx*k+ny+nz*k*k; que.x=nx; que.y=ny; que.z=nz; d[que.time]=d[ue.time]+1; q[rear++]=que; } } } } int main() { int i,j,o,n1,m1,l1; char nima[10]; while(~scanf("%s%d",nima,&k)) { for(o=0;o<k;o++) { for(i=0;i<k;i++) { for(j=0;j<k;j++) { cin>>map[o][i][j]; visit[o][i][j]=0; d[o*k*k+i*k+j]=0; } } } scanf("%d%d%d%d%d%d%s",&n1,&m1,&l1,&n,&m,&l,nima); flag=0; visit[l1][n1][m1]=1; BFS(n1,m1,l1); if(flag) printf("%d %d\n",k,d[l*k*k+n*k+m]); else printf("NO ROUTE\n"); } }