UVa 532 - Dungeon Master

Summary
Given a set of maps which constitute a 3-Dimensional world (a dungeon), determine whether it is possible to travel from the starting cell (marked as 'S') to the ending cell (marked as 'E') and calculate the minimal time-cost for the travelling if possible.

Explanation
A standard Breadth-First Search would be able to solve the problem. Consider this adjacency criterion: Cell B is adjacent to Cell A if and only if we can arrive B from A with one single move.

Gotchas

 * Be aware of infinite cycles. Mark old cells as 'visited'.
 * To handle the judge input, a queue with large size is needed.
 * Watch out for queue size overflow. DO NOT push redundant elements. Check before you push, not after you pop. Too many elements to be pushed to the queue would result in a TLE with a dynamic-size queue or a RE with a static-size queue.

Implementations

 * It might be good to use the STL queue container or a circular queue.
 * Code All the Problems

Input
3 4 5 S.... .###. .##..




 * 1) E
 * 1) E
 * 1) E
 * 1) E

1 3 3 S##
 * E#

1 30 30 .############################# .#############################
 * 1) ...........................E#
 * 2) .#.#.#.#.#.#.##S#.#.#.#.#.#.#
 * 1) .#.#.#.#.#.#.##S#.#.#.#.#.#.#
 * 1) .#.#.#.#.#.#.##S#.#.#.#.#.#.#
 * 1) .#.#.#.#.#.#.##S#.#.#.#.#.#.#
 * 1) .#.#.#.#.#.#.##S#.#.#.#.#.#.#
 * 1) .#.#.#.#.#.#.##S#.#.#.#.#.#.#
 * 1) .#.#.#.#.#.#.##S#.#.#.#.#.#.#
 * 1) .#.#.#.#.#.#.##S#.#.#.#.#.#.#
 * 1) .#.#.#.#.#.#.##S#.#.#.#.#.#.#
 * 1) .#.#.#.#.#.#.##S#.#.#.#.#.#.#
 * 1) .#.#.#.#.#.#.##S#.#.#.#.#.#.#
 * 1) .#.#.#.#.#.#.##S#.#.#.#.#.#.#
 * 1) .#.#.#.#.#.#.##S#.#.#.#.#.#.#
 * 1) .#.#.#.#.#.#.##S#.#.#.#.#.#.#

5 10 20 S.##.####.#...##..#. ...#..##.###.#...... ......#.###.###.##.# .....#..##..##..#.## ..#.#...#.#.##...##. ..#.###.#..#...#....

..#.....#####.##.... .#.#.#......#..#.... ..#.###..#..#####.#. ...#...####.#..#..#. ......#..#.###...#..

.###...##.##..##.... .###.#..##.####.#### .######.....#..##... .#..######.##......# .#...#...##.#....#..

.......####..##.##.. ....##.####....##.## .#########.#.##...## .#.##....#..####...# .#..###.##.#######.. ..##..###.##..####.. .#....#.....##.#.#.. .#.#.#..#...######.#

..#..#.#.####.#####. ....###..#....##.### .#..#..####.#.####.# .##..#..##.#.###....
 * 1) .###...##.##..###.E
 * 1) .###...##.##..###.E
 * 1) .###...##.##..###.E

0 0 0

Output
Escaped in 11 minute(s). Trapped! Escaped in 418 minute(s). Escaped in 40 minute(s).