You are given a rectangular map in which each space is marked with one of three characters:
'.' (open), 'B' (a brick), or '#' (an indestructible block).
Walls made of indestructible blocks surround the field on all sides, but are not shown on the map. A ball is bouncing around this
map, destroying bricks, and your task is determine how long it takes the ball to destroy all the bricks.
The top left space of the map is always open, and this is where the ball begins. More specifically, the ball begins at time 0
in the middle of the top edge of this space (see the diagram in Example 0). The ball is
traveling diagonally down and to the right at a speed of half a meter per second vertically, and half a meter per second
horizontally. Each space is 1 meter square, so the ball crosses half a space vertically and half a space horizontally each
second.
Whenever the ball strikes the edge of an obstacle--either a brick or an indestructible block--it bounces off at an angle
perpendicular to its incoming path. The ball will never hit two obstacles simultaneously. Whenever the ball bounces
off a brick, the brick is destroyed and removed from the map.
Your method should return the time at which the last brick is destroyed. If one or more bricks will never be
destroyed, return -1.
|