DWITE Online Computer Programming Contest
November 2008
Problem 5
Water damage

There's a shady water dam that might break, so an insurance company wants to calculate the possible damage given a series of scenarios. Given a topography of the region, and the amount of water projected to spill out, the goal is to find out how many of the targets of interest will be submerged, after the water settles.

The input file DATA5.txt will contain 5 sets of input. First line is an integer W, amount of water expected. Second line is an integer C, number of columns in a map. Third line is an integer R, number of rows in a map. Next R lines describe the layout of the area. 1 <= C, R, <= 10. 1 <= W <= 100. Dot . is empty space that could be flooded. Number sign # is land. Capital letter A is a point of interest; there will be at least 1; it should be treated as empty space, but only this area counts for points. Each set is separated by a whitespace line.

The output file OUT5.txt will contain 5 lines, an integer number of points of interest under water.

Technical details: Water originates at top-left of the map. Each unit of water occupies one cell on the map. Water normally falls down. If there's ground below, it will move to the right. Once in place (can no longer flow), it could be treated as solid ground, as far as the movement of other units of water is concerned.

Step-by-step diagram: 2 units of water, C=4 x R=3 layout. Asterisk * represents a moving unit of water. 2nd unit of water reaches A at the bottom. Even though A at the top was passed by water, it remains un-submerged at the end, so it's not counted towards the output sum.

*.A. .*A. ..A. *.A. .*A. ..*. ..A* .... ..A. 
#.#. #.#. #*#. #*#. #*#. #*#. #*#. #*#* #*#. 
###A ###A ###A ###A ###A ###A ###A ###A ###* 
		  

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

4
4
3
..A.
#.#.
###A

5
4
3
..A.
#.#.
###A
		        
Sample Output:
1
1
2