DWITE Online Computer Programming Contest

Ricochet Robot

October 2010
Problem 5

That vacuum robot from Problem 2 did not work out that well – its brakes don’t work. Luckily it safely stops whenever it hits a wall, so maybe it’s not all that bad? We can use software to plan out the shortest routes to bounce around from one spot to another, in a 10-by-10 room.

The input file DATA5.txt will contain 5 sets of inputs, each a 10-by-10 room as described above. For a visual break in test cases, there will be an additional line of 10 dashes after every input set.

The output file OUT5.txt will contain 5 lines, each an integer representing the minimum number of moves necessary to get from point A to point B.

Notes: Test cases will be such that it’s always possible to come to a stop at point B. The solution requires a stop, not simply a pass over the point. A robot can move in any of the 4 directions, and will continue moving until hitting a wall or an edge of the room.

Sample Input (first 2 shown):
....#.....
..A.......
....B#....
...#......
..........
..........
..........
..........
..........
..........
----------
....#.....
..A.......
....B#....
#..#......
..........
..........
..........
..........
..........
..........
----------
Sample Output (first 2 shown):
4
3