天天看點

ACM-三維BFS之Asteroids!——hdu1240 Asteroids!

time limit: 2000/1000 ms (java/others)    memory limit: 65536/32768 k (java/others)

total submission(s): 3161    accepted submission(s): 2108

problem description

you‘re in space.

you want to get home.

there are asteroids.

you don‘t 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,0,0>. therefore, each component of each coordinate vector will 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 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

sample output

source

題目:

這道題就是三維廣搜,當時剛做完 這道題,感覺很類似。

于是把這道題代碼拿過來改了改就交上去。

發現過不了。

經過ym提醒,發現是i,j,k問題。

輸入的n*n*n的圖,最慢增長的應該是 z軸的數字。

是以z軸的應該用i來代替讀入,因為三重循環的時候i,j,k中i是增長最慢的。

簡單點說:就是把曾經  cin>>map[i][j][k]改為cin>>map[j][k][i]

why?看我之前說的。

然後普普通通的bfs,0ms  a咯~