DWITE Online Computer Programming Contest, January 2008, Problem 4
Sometimes an open field could be as much of a maze as narrow tunnels. Given an obstacle in an otherwise empty room, what is the shortest path around it?
The input file will contain five sets of data, each a by character matrix. There will be a line of dashes after each set, to visually delimit sets of data. The character representations are as follows:
.
- empty space#
- wallX
- one of the ends
The output will contain five lines – each an integer distance between the two points marked with .
There will always be only two spots per set. There will always be a valid path. Valid steps are into any adjacent empty space; diagonal steps are legal. Refer to sample data for examples.
Sample Input
..........
..........
..........
....#.....
....#.....
X...#...X.
....#.....
....#.....
..........
..........
----------
..........
..........
........#.
........#.
X...#####X
...#......
..#.......
..........
..........
..........
----------
Sample Output
8
9
Problem Resource: DWITE
Comments
Why do I get Java array index out of bounds exception? Can someone help me out?
line 122, should be x + 1, not x - 1