#P3457. [POI2007] POW-The Flood
[POI2007] POW-The Flood
题目描述
Byteburg, the capital of Byteotia, is a picturesque city situated in a valley in the midst of mountains. Unfortunately, recent heavy rainfall has caused a flood - all the Byteburg is now completely under water. Byteasar, the king of Byteotia, has summoned his most enlightened advisors, including you, to a council. After long deliberations the council agreed to bring a few pumps, set them up in the flooded area and drain Byteburg.
The king has asked you to determine the minimum number of pumps sufficing to drain the city.
You are provided with a map of the city and the valley it is situated in. The map is in the shape of a rectangle, divided into unitary squares. For each such square the map tells its height above sea level and alsowhether it is a part of Byteburg or not. The whole area depicted in the map is under water. Furthermore, it issurrounded by much higher mountains, making the outflow of water impossible. Obviously, there is no needto drain the area that does not belong to Byteburg.
Each pump can be placed in any unitary square depicted in the map. The pump will be drawing thewater until its square is completely drained. Of course, the communicating tubes principle makes its work, so draining one square results in lowering the water level or complete draining of those squares from which the water can flow down to the one with the pump. Water can flow only between squares with a common side (or, more exact, squares whose projections onto horizontal plane have a common side, since the squares may be at different level). Apart from that, the water obviously only flows down.
Task
Write a programme that:
-
reads description of the map from the standard input,
-
determines the minimum number of pumps needed to drain whole Byteburg,
-
writes out the outcome to the standard output.
输入格式
In the first line of the standard input there are two integers and , separated by a single space, . The following lines contain the description of the map. The 'th line describes the 'th row of unitary squares in the map. It contains integers , separated by single spaces, , . The number describes the 'th square of the 'th line. The ground level in this square is above sea level. If , then the square is part of Byteburg, otherwise it is outside the city. Notice, that the area of Byteburg need not be connected. In fact the city may have several separate parts.
输出格式
Your programme should write out one integer to the standard output - the minimum number of pumpsneeded to drain Byteburg.
题目大意
题目描述
译自 POI 2007 Stage 2. Day 1「The Flood」
你有一张 的地图,地图上所有点都被洪水淹没了。你知道地图上每个网格的海拔高度,其中一部分点属于 Byteburg 城。你需要放置尽可能少的巨型抽水机,将 Byteburg 城从洪水中解救出来。巨型抽水机会抽干该格子的所有水,直到该格子不被洪水淹没为止。
水会在有公共边的格子间从高向低流动。
输入格式
第一行两个整数 ()。
接下来 行每行 个整数 $x_{i1}, x_{i2}, \ldots, x_{in} (-1000 \le x_{ij} \lt 1000)$,表示地图。第 行第 列格子的海拔高度为 ,且如果 ,则这个格子在 Byteburg 城内,否则在城外。不保证 Byteburg 城形成一个连通块。
输出格式
输出一行一个整数,表示最少需要的抽水机的数量。
样例解释
翻译来自于 LibreOJ。
6 9
-2 -2 -1 -1 -2 -2 -2 -12 -3
-2 1 -1 2 -8 -12 2 -12 -12
-5 3 1 1 -12 4 -6 2 -2
-5 -2 -2 2 -12 -3 4 -3 -1
-5 -6 -2 2 -12 5 6 2 -1
-4 -8 -8 -10 -12 -8 -6 -6 -4
2