Logo
(追記) (追記ここまで)

5369번 - Asteroid Field 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB101797278.261%

문제

Plot a path through the asteroid field. Given a starting location, final destination, and a description of the asteroid fields plot a shortest path that takes you from the starting location to the final destination without running into any asteroids. The asteroid field is described using a mxm grid of characters with

  • s: for starting location
  • d: for final location
  • -: for open space
  • *: asteroid

Here is an example of a 4x4 grid.

s*-*
-*-*
----
*-*d

Your ship can move up, down, left, and right (not diagonally). Each position in a mxm grid will be assigned an integer between 0 and m2-1 as follows.

입력

The first line will have a positive integer n representing the number of data sets. The first line of each data set will contain an integer m, followed by m lines, and each line will contain m characters. The character s will always be in the top left corner and d will always be in the bottom right corner.

출력

For each data set print the minimal number of moves needed to reach the destination or -1 if there is no solution.

제한

예제 입력 1

2
4
s*-*
-*-*
--*-
*-*d
6
s*---*
-*-*--
---**-
***---
--*-**
*-*--d

예제 출력 1

-1
18

힌트

출처

School > PLU High School Programming Contest > PLU 2011 > Advanced 8번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /