Problem B. Rain
2016-07-17 12:35
441 查看
Problem B. Rain
This contest is open for practice. You can try every problem as many times as you like, though we won't keep track of which problems you solve. Read the Quick-StartGuide to get started.
Small input 9 points | Solve B-small |
Large input 15 points | Solve B-large Judge's response for last submission: Correct. |
Problem
There's an island in the sea. The island can be described as a matrix with R rows and Ccolumns, with H[i][j] indicating the height of each unit cell. Following is an example of a 3*3 island:3 5 5 5 4 5 5 5 5
Sometimes, a heavy rain falls evenly on every cell of this island. You can assume that an arbitrarily large amount of water falls. After such a heavy rain, some areas of the island (formed of one or more unit cells joined along edges) might collect water. This
can only happen if, wherever a cell in that area shares an edge (not just a corner) with a cell outside of that area, the cell outside of that area has a larger height. (The surrounding sea counts as an infinite grid of cells with height 0.) Otherwise, water
will always flow away into one or more of the neighboring areas (for our purposes, it doesn't matter which) and eventually out to sea. You may assume that the height of the sea never changes. We will use W[i][j] to denote the heights of the island's cells
after a heavy rain. Here are the heights of the example island after a heavy rain. The cell with initial height 4 only borders cells with higher initial heights, so water will collect in it, raising its height to 5. After that, there are no more areas surrounded
by higher cells, so no more water will collect. Again, note that water cannot flow directly between cells that intersect only at their corners; water must flow along shared edges.
Following is the height of the example island after rain:
3 5 5 5 5 5 5 5 5
Given the matrix of the island, can you calculate the total increased height sum(W[i][j]-H[i][j]) after a heavy rain?
Input
The first line of the input gives the number of test cases, T. T test cases follow.The first line of each test case contains two numbers R and C indicating the number of rows and columns of cells on the island. Then, there are R lines of C positive integers each. The j-th
value on the i-th of these lines gives H[i][j]: the height of the cell in the i-th row and the j-th column.
Output
For each test case, output one line containingCase #x: y, where
xis the test case number (starting
from 1) and
yis the total increased height.
Limits
1 ≤ T ≤ 100.1 ≤ H[i][j] ≤ 1000.
Small dataset
1 ≤ R ≤ 10.1 ≤ C ≤ 10.
Large dataset
1 ≤ R ≤ 50.1 ≤ C ≤ 50.
Sample
Input | Output |
3 | Case #1: 1 Case #2: 3 Case #3: 0 |
In case 2, the island looks like this after the rain:
5 5 5 1 5 2 2 5 5 2 5 5 5 2 5 8
Case 3 remains unchanged after the rain.
这是题旧题,参考我的博客 :http://blog.csdn.net/xishisugan/article/details/8712035poj2227
相关文章推荐
- 自学——PaintAndPath
- 修复 apt-get update “the following signatures couldn’t be verified because the public key is not avai
- [区间dp] hdu 2476 string painter
- 19. ubuntu 16.04 LTS 安装mailx
- UVALive 6893 The Big Painting hash
- HDU 2476 String painter (区间DP)
- UVALive 6885 Flowery Trails 最短路
- HighAvailability
- UVA 442 Matrix Chain Multiplication
- Mybaits深入了解(三)----mybatis开发Dao的方法
- Mybaits深入了解(二)—-入门实例
- main中的数组args传值
- LeetCode-336.Palindrome Pairs
- hdu 1789 Doing Homework again 贪心
- 邮件服务器(postfix + dovecot + extmail + extman + MailScanner + spamassassin + ClamAV )
- 微软开源Malmo AI项目平台 利用Minecraft构建复杂机器人任务
- Training2:位操作训练
- HDU 5319 Painter(暴力枚举)
- 磁盘阵列 RAID 技术原理详解
- 浅谈RAID写惩罚(Write Penalty)与IOPS计算