Problem Descriptionyou ' re in space.
You want to get home.
There is asteroids.
You don ' t want-to-hit them.
Inputinput 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.
Outputfor 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 inputstart 1o0 0 0 0ENDSTART 3xxxxxxxxxoooooooooxxxxxxxxx0 0 2 1ENDSTART 5OOOOOOOOOOOOOOOOOOOOOOOOOOOOOO oooo OOOOOOOOOOOOOOOOXXXXXXXXXXXXXXXXXXXXXXXXXOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO0 0 4 4END
Sample Output1 4NO ROUTE//is a wide search ~ translation is flawed ....
#include <iostream>#include<cstring>#include<queue>using namespacestd;Charmap[ the][ the][ the];intvisit[ the][ the][ the];Chara[6];intN;intK1,k2,k3,e1,e2,e3;intto[6][3]={{1,0,0},{-1,0,0},{0,1,0},{0,-1,0},{0,0,1},{0,0,-1}};structnode{intx, Y, Z intstep;};intGointXintYintz) { if(0<=x&&x<n&&0<=y&&y<n&&0<=z&&z<n&&map[x][y][z]=='O') return 1; return 0;}intBFS () {node st,ed; Queue<node>Q; St.x=K1; St.y=K2; St.z=K3; St.step=0; memset (Visit,0,sizeof(visit)); VISIT[K1][K2][K3]=1; Q.push (ST); while(!Q.empty ()) {St=Q.front (); Q.pop (); if(st.x==e1&&st.y==e2&&st.z==E3) {cout<<n<<" "<<st.step<<Endl; return 0; } for(intI=0;i<6; i++) {ed.x=st.x+to[i][0]; Ed.y=st.y+to[i][1]; Ed.z=st.z+to[i][2]; if(Go (ed.x,ed.y,ed.z) &&visit[ed.x][ed.y][ed.z]==0) {Visit[ed.x][ed.y][ed.z]=1; Ed.step=st.step+1; Q.push (ed); } }} cout<<"NO ROUTE"<<Endl; return 0;}intMain () { while(cin>>a) {cin>>N; memset (Map,0,sizeof(map)); for(intI=0; i<n;i++) for(intj=0; j<n;j++) for(intk=0; k<n;k++) Cin>>Map[i][j][k]; CIN>>k1>>k2>>k3>>e1>>e2>>E3; MAP[E1][E2][E3]='O'; CIN>>A; BFS (); } return 0;}
HDU 1240 Asteroids!