Problem 1901 --Problem D - Maze

1901: Problem D - Maze

"
Time Limit $10$ 秒/Second(s) Memory Limit $512$ 兆字节/Megabyte(s)
提交总数 $4$ 正确数量 $2$
裁判形式 标准裁判/Standard Judge 我的状态 尚未尝试
难度 分类标签

Problem D - Maze

You have been blindfolded and deposited someplace in a maze. You have no idea where you are. You do know, however, that the maze is laid out on a grid, and that each grid location is either blocked or free. In fact, you have memorized a map of the maze. Also, your magnetic personality allows you to always sense which direction is north.

In this maze, you have four possible moves: north, south, east, and west. Your task is to find the shortest sequence of moves that will guarantee your escape, regardless of your initial placement in the maze. You have "escaped" whenever you reach a square on an outside edge of the grid (and if you start there, then you've already escaped). Further moves are irrelevant once you have escaped. If you try to walk into a wall, you will simply stay in the same spot.

You may assume that it is possible to escape from every unblocked position in the maze.

Input consists of a positive integer n <= 8, followed by n lines giving the rows of an n by n grid. This grid describes the maze you are trapped in. Written on the screen, north is up. Blocked locations are denoted by the character "O" (that's an uppercase "o"), while unblocked locations are indicated by the character ".". 

Output consists of a number of lines, each consisting of one of "north", "south", "east", or "west", indicating the shortest sequence of moves that guarantees escape for any possible unblocked starting position.

4
OO.O
...O
OO..
O..O
east
north

推荐代码 查看1901 所有题解 上传题解视频得图灵币

本题记录 用 户(点击查看用户) 运行号(点击购买题解) 时 间
算法最快[$207 $ms] 计爱玲 350518 2018-12-19 10:14:41
内存最少[$19532 $KB] AOJ大管家 84416 2017-04-27 15:28:47
第一AC AOJ大管家 84416 2017-04-27 15:28:47
第一挑战 AOJ大管家 84416 2017-04-27 15:28:47

赛题来源/所属竞赛 NA N/A

竞赛编号 竞赛名称 竞赛时间 访问比赛