88 人解决,155 人已尝试。
117 份提交通过,共有 550 份提交。
4.5 EMB 奖励。
单点时限: 3.0 sec
内存限制: 256 MB
You find yourself trapped in a large rectangular room, made up of large square tiles; some
are accessible, others are blocked by obstacles or walls. With a single step, you can move
from one tile to another tile if it is horizontally or vertically adjacent (i.e. you cannot move
diagonally).
To shake off any people following you, you do not want to move in a straight line. In fact,
you want to take a turn at every opportunity, never moving in any single direction longer
than strictly necessary. This means that if, for example, you enter a tile from the south,
you will turn either left or right, leaving to the west or the east. Only if both directions
are blocked, will you move on straight ahead. You never turn around and go back!
Given a map of the room and your starting location, figure out how long it will take you
to escape (that is: reach the edge of the room).
On the first line an integer t (1 <= t <= 100): the number of test cases. Then for each test
case:
and width of the room;
of . (period; an accessible space), # (a blocked space) or @ (your starting location).
There will be exactly one @ character in each room description.
For each test case:
the room, or -1 if no escape is possible.
2 9 13 ############# #@..........# #####.#.#.#.# #...........# #.#.#.#.#.#.# #.#.......#.# #.#.#.#.#.#.# #...........# #####.####### 4 6 #.#### #.#.## #...@# ######
31 -1