G-asteroids!Time
limit:MS
Memory Limit:32768KB
64bit IO Format:%i64d &%i64u SubmitStatus
Description
You ' re in space.
You want to get home.
There is asteroids.
You don ' t want-to-hit them.
Input
Input to this problem would consist of a (Non-empty) series of up to data sets. Each data set is formatted according to the following description, and there would be no blank lines separating data s Ets.
A Single Data set have 5 components:
Start Line-a single line, "Start N", where 1 <= n <= 10.
Slice list-a series of N slices. Each slice are an n x n matrix representing a horizontal slice through the asteroid field. Each position in the matrix would be one of the 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 would 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 would be integers separated by individual spaces.
End Line-a single line, "End"
The origin of the coordinate system is <0,0,0>. Therefore, each component of each coordinate vector would be an integer between 0 and N-1, inclusive.
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 would be in empty space.
Output
For each data set, there'll be exactly one output set, and there'll be no blank lines separating output sets.
A single output set consists of a single line. If a route exists, the line would be in the format "X Y", where X was the same as N from the corresponding input data set an D 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 would be "no route" instead.
A move can only is in one of the six basic directions:up, down, left, right, forward, back. Phrased more precisely, a move would either increment or decrement a single component of your current position vectors by 1.
Sample Input
Sample Output
/*author:2486memory:1452 kbtime:0 mslanguage:g++result:accepted*/#include <cstring> #include <algorithm > #include <queue>using namespace std;const int Maxn=+5;char Maps[maxn][maxn][maxn];bool VIS[MAXN][MAXN][MAXN ];char op[10];int n;int a[10];int dx[]={0,0,1,0,-1,0};int dy[]={0,0,0,1,0,-1};int dz[]={1,-1,0,0,0,0};struct obje{int X,y,z,steps; Obje (int x,int y,int z,int steps): x (x), Y (y), Z (z), steps (steps) {} bool operator< (const obje &a) const{retur N steps>a.steps; }};void BFs () {priority_queue<obje>g; G.push (Obje (a[0],a[1],a[2],0)); while (! G.empty ()) {Obje e=g.top (); G.pop (); if (e.x<0| | e.y<0| | e.z<0| | e.x>=n| | e.y>=n| | e.z>=n| | maps[e.x][e.y][e.z]== ' x ' | | VIS[E.X][E.Y][E.Z]) continue; Vis[e.x][e.y][e.z]=true; if (E.x==a[3]&&e.y==a[4]&&e.z==a[5]) {printf ("%d%d\n", n,e.steps); Return } for (int i=0;i<6;i++) {int nx=e.x+dx[i]; int ny=e.y+dy[i]; int nz=e.z+dz[i]; G.push (Obje (nx,ny,nz,e.steps+1)); }} printf ("NO route\n");} int main () {#ifndef online_judge//this blog has introduced its usefulness freopen ("D://imput.txt", "R", stdin); #endif//Online_judgewhile (~SCANF ("%s%d", Op,&n)) {for (int. i=0;i<n;i++) {for (int j=0;j<n;j++) { scanf ("%s", Maps[i][j]); }} for (int i=5;i>=0;i--) {scanf ("%d", &a[i]); } scanf ("%s", op); BFS ();} return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
asteroids!-Bare BFS