当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。
Once Farmer John was washing his dirty clothes. Staring at lots of buckets, he was inspired suddenly. He said, "I can make a 3-dimensional musical water-fence (abbr. 3dmwf) like this."
After ages Farmer John shaped a piece of wood into a perfect 3dmwf. As figure A illustrates, the 3dmwf is an array of n rows and m columns of squares. And each square in the ith row and jth column is entirely occupied by a block, bij of height hij. And there is a tap over each block which can pour water.
Figure A: A 3-dimensional musical water-fenceheights of the blocks are
5 12 11 8 15 2 4 14 16 1 3 7 13 10 9 6
If Farmer John turns on a tap some water will be poured onto the block under that tap due to the gravity. As soon as the water crashes onto the block a dulcet sound will be made. And the tune of the sound is determined by the height of the block that makes the sound. Farmer John dislikes the same tune made by two different blocks. So no blocks has the same height. For simplicity we assume that the height of each block is between 1 and n × m.
We define pour(i,j,k) as the operation pouring k units of water onto the block bij. It is apparent that after pouring water onto 3dmwf probably some water will remain in concave holes.
When we pour(i,j,k) one and only one of the following two cases occurs:
(1) There is no water on the bij and there is some neighboring block whose horizontal line is lower than the bij.
Let Sum be the number of those neighboring blocks. Then pour(i,j,k) is equivalent to pour(i',j',k⁄Sum) where bi'j' is one of those neighboring blocks. That means the water will flow to all the lower neighboring blocks equally.
For example, in the previous figure,
pour(4,1,27)<=>(2) There is some water on the bij or there is no neighboring block whose horizontal line is lower than bij.
The k units of water will be mixed together with the water already on the bij. Then the horizontal line of those mixed the water will rise up until impossible because there is an exit that makes the water out of the concave hole.
For example, in the previous figure, continuing analyzing the last example,
(A)pour(3,2,3). After pouring 1 unit of water the horizontal lines of all blocks will become
5 | 12 | 11 | 8 |
15 | 2 | 4 | 14 |
16 | 2 | 3 | 7 |
13 | 10 | 9 | 6 |
And then after pouring 2 units of water the chart above will be become
5 | 12 | 11 | 8 |
15 | 3 | 4 | 14 |
16 | 3 | 3 | 7 |
13 | 10 | 9 | 6 |
(B)pour(3,3,1). After pouring 1 unit of water the chart above will become
5 | 12 | 11 | 8 |
15 | 31⁄3 | 4 | 14 |
16 | 31⁄3 | 31⁄3 | 7 |
13 | 10 | 9 | 6 |
(C)If we go on pouring a lot of water onto the concave hole, the chart above will become
5 | 12 | 11 | 8 |
15 | 7 | 7 | 14 |
16 | 7 | 7 | 7 |
13 | 10 | 9 | 6 |
The redundant water will flow away through the b34.
On a sunny day, after farming on his vast farm, Farmer John was exhausted. He wanted to listen to some dulcet music. So he composed a long music score for the 3dmwf. The music score is a list of pour(i,j,k) arranged in specific order. And now he invited his friends, Wang Dong, Guo Huayang, Chen Danqi, He Yijun to help him operate 3dmwf.
You know, Farmer John is an abstemious farmer. He doesn't want to waste too much water for playing music on 3dmwf. Could you tell him the volume of the total waste water?
Sample Input 1 4 4 5 12 11 8 15 2 4 14 16 1 3 7 13 10 9 6 1 4 1 27 Sample Input 2 4 4 5 12 11 8 15 2 4 14 16 1 3 7 13 10 9 6 2 4 1 27 2 2 100
Sample Output 1 23.00 Sample Output 2 109.00
Case time limit(单组数据时间限制) | 4000MS |
时间上限 | 内存上限 |
8000 | 65536 |