题意翻译

Description 你手头有一张该市的地图。这张地图是边长为 m∗n 的矩形,被划分为m∗n个1∗1的小正方形。对于每个小正方形,地图上已经标注了它的海拔高度以及它是否是该市的一个组成部分。地图上的所有部分都被水淹没了。并且,由于这张地图描绘的地面周围都被高山所环绕,洪水不可能自动向外排出。显然,我们没有必要抽干那些非该市的区域。

每个巨型抽水机可以被放在任何一个1∗1正方形上。这些巨型抽水机将持续地抽水直到这个正方形区域里的水被彻底抽干为止。当然,由连通器原理,所有能向这个格子溢水的格子要么被抽干,要么水位被降低。每个格子能够向相邻的格子溢水,“相邻的”是指(在同一高度水平面上的射影)有公共边。

Input

第一行是两个数m,n(1<=m,n<=1000).

以下 m 行,每行 n 个数,其绝对值表示相应格子的海拔高度;若该数为正,表示它是该市的一个区域;否则就不是。

请大家注意:所有格子的海拔高度其绝对值不超过 1000 ,且可以为零.

Output

只有一行,包含一个整数,表示至少需要放置的巨型抽水机数目。

感谢@FlashHu 提供的翻译

题目描述

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 m×nm\times nm×n 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 mmm and nnn , separated by a single space, 1≤n,m≤1 0001 \le n, m \le 1\ 0001≤n,m≤1 000 . The following mmm lines contain the description of the map. The (i+1)(i+1)(i+1) 'th line describes the iii 'th row of unitary squares in the map. It contains nnn integers xi,1,xi,2,...,xinx_{i,1}, x_{i,2}, ..., x_{i_n}xi,1​,xi,2​,...,xin​​ , separated by single spaces, −1 000≤xi,j≤1 000-1\ 000 \le x_{i,j} \le 1\ 000−1 000≤xi,j​≤1 000 , xi,j≠1000x_{i,j} \ne 1000xi,j​≠1000 . The number xi,jx_{i,j}xi,j​ describes the jjj 'th square of the iii 'th line. The ground level in this square is ∣xi,j∣|x_{i,j}|∣xi,j​∣ above sea level. If xi,j>0x_{i,j} > 0xi,j​>0
, 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.

输入输出样例

输入样例#1:

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
输出样例#1:

2

Solution:

  本题题意描述生涩,考思维,重细节,贼有意思。

  简单讲下题意:给定点的海拔(绝对值),正负分别表示的是城市或者非城市,城市的水一定要抽干,然后非城市的水就无所谓,关键的问题是,水的流通性是满足连通器原理(即$4,-3,4$这样的数据只需要在任意一个$4$处放一个抽水机就$OK$了),求最少要放多少个抽水机(可以在任意一个格子上放)。

  考虑一个点$a$放了抽水机,另一个点$b$不用放抽水机也能抽干,只有存在$a\rightarrow b$的一条路径且经过的点(包括$a$)的海拔不超过$b$的海拔时才能成立。于是考虑对点按海拔从小到大排序,然后扫一遍每个点,对其四个方向上的点进行判断,若邻点海拔不超过当前点的海拔,则合并这两个点(说明只要邻点被抽干则当前点也能被抽干)。对于为城市的点,若其无法被周围的点抽干或者能连通但其周围的点无法连向一个放了抽水机的连通块,则对其打个标记并累加答案,合并集合的过程用并查集维护,然后标记关系也在合并时转移一下就好了。

  细节就是一定要将同海拔的点合并完后再去放抽水机,因为对于$3,3,2,1$这种数据,排序后$1,2,3,3,$,从前往后扫会$1,2,3$为一个连通块,而孤立了最后一个$3$,正确的方式是扫到了$3$时,将所有的$3$都先合并,最后再安排放抽水机就不会影响答案了。

代码:

#include<bits/stdc++.h>
#define il inline
#define ll long long
#define For(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define Bor(i,a,b) for(int (i)=(b);(i)>=(a);(i)--)
using namespace std;
const int N=,dx[]={,-,,},dy[]={,,,-};
int n,m,fa[N*N],id[N][N],vis[N*N],a[N][N],cnt,ans;
struct node{
int x,y,h;
bool operator<(const node &a)const {return h<a.h;}
}mp[N*N]; il int gi(){
int a=;char x=getchar();bool f=;
while((x<''||x>'')&&x!='-')x=getchar();
if(x=='-')x=getchar(),f=;
while(x>=''&&x<='')a=(a<<)+(a<<)+x-,x=getchar();
return f?-a:a;
} il int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);} int main(){
n=gi(),m=gi();
For(i,,n) For(j,,m) {
a[i][j]=gi();
mp[++cnt].x=i,mp[cnt].y=j,id[i][j]=cnt;
mp[cnt].h=(a[i][j]>?a[i][j]:-a[i][j]);
}
sort(mp+,mp+cnt+);
For(i,,cnt) fa[i]=i;
For(i,,cnt){
For(j,,){
int xx=mp[i].x+dx[j],yy=mp[i].y+dy[j];
if(xx>&&xx<=n&&yy>&&yy<=m){
if(mp[i].h>=abs(a[xx][yy])) {
int fx=find(id[xx][yy]),fy=find(id[mp[i].x][mp[i].y]);
vis[fy]|=vis[fx],fa[fx]=fy;
}
}
}
if(mp[i].h!=mp[i+].h)
for(int j=i;mp[j].h==mp[i].h;j--)
if(a[mp[j].x][mp[j].y]>){
int fx=find(id[mp[j].x][mp[j].y]);
if(!vis[fx]) vis[fx]=,ans++;
} }
cout<<ans;
return ;
}

P3457 [POI2007]POW-The Flood的更多相关文章

  1. 洛谷P3457 [POI2007]POW-The Flood [并查集,模拟]

    题目传送门 pow 题意翻译 Description 你手头有一张该市的地图.这张地图是边长为 m∗n 的矩形,被划分为m∗n个1∗1的小正方形.对于每个小正方形,地图上已经标注了它的海拔高度以及它是 ...

  2. 10月清北学堂培训 Day 6

    今天是黄致焕老师的讲授~ T1 自信 AC 莫名 80 pts???我还是太菜了!! 对于每种颜色求出该颜色的四个边界,之后枚举边界构成的矩阵中每个元素,如果不等于该颜色就标记那种颜色不能最先使用. ...

  3. [洛谷3457][POI2007]POW-The Flood

    洛谷题目链接:[POI2007]POW-The Flood 题意翻译 Description 你手头有一张该市的地图.这张地图是边长为 m∗n 的矩形,被划分为m∗n个1∗1的小正方形.对于每个小正方 ...

  4. [POI2007]洪水pow 题解

    [POI2007]洪水pow 时间限制: 5 Sec  内存限制: 128 MB 题目描述 AKD市处在一个四面环山的谷地里.最近一场大暴雨引发了洪水,AKD市全被水淹没了.Blue Mary,AKD ...

  5. [POI2007]POW-The Flood(并查集)

    [POI2007]POW-The Flood Description AKD 市处在一个四面环山的谷地里.最近一场大暴雨引发了洪水,AKD 市全被水淹没了.Blue Mary,AKD 市的市长,召集了 ...

  6. bzoj1104: [POI2007]洪水pow

    #include <iostream> #include <cstdio> #include <cmath> #include <cstring> #i ...

  7. 【BZOJ】1104: [POI2007]洪水pow

    题意 给一个\(n * m(1 \le n, m \le 1000)\)的矩阵,如果\(a_{i, j}\)为正表示城市.\(|a_{i, j}|(|a_{i, j}| \le 1000)\)是格子\ ...

  8. [POI2007]洪水pow 并查集

    我们先得出一个结论:水泵要建在城市上.因为如果在非城市上建能把其他一些城市抽干,那么在城市上建也是一个效果(自己画图感性理解一下) 然后我们明白抽水的条件:周围的高度要>=自身的高度,这样会抽完 ...

  9. Luogu345: [POI2007]POW-The Flood

    题意 见luogu Sol 贪心 从小到大枚举高度,把小于等于这一高度的相邻格子用并查集合并 那么这个集合内的所有格子都一定可以由这个集合内的一个最低点抽完水 那么合并之后(一定要在合并之后) 判断这 ...

随机推荐

  1. 转:java中的定时任务

    引自:http://www.cnblogs.com/wenbronk/p/6433178.html java中的定时任务, 使用java实现有3种方式: 1, 使用普通thread实现 @Test p ...

  2. JAVAOOP I/O

    程序的主要任务就是操作数据,通过允许程序读取文件的内容或向文件写入数据,可以使程序应用更加广泛. I/O(input/output) 在不同操作系统之下,所占的字节数也不同,一般认为 8.1.1使用F ...

  3. Tornado学习

    为什么用Tornado? 异步编程原理 服务器同时要对许多客户端提供服务,他的性能至关重要.而服务器端的处理流程,只要遇到了I/O操作,往往需要长时间的等待.   屏幕快照 2018-10-31 上午 ...

  4. 安装docker和更改docker镜像下载目录

    centos6.x系列: yum install http://mirrors.yun-idc.com/epel/6/i386/epel-release-6-8.noarch.rpm yum inst ...

  5. 吐血分享:QQ群霸屏技术教程2017(活跃篇)

    热门词的群排名,在前期优化准备充分的情况下,活跃度不失为必杀技. 在<吐血分享:QQ群霸屏技术(初级篇)>中,我们提及到热门词的群排名,有了前面的基础,我们就可以进入深度优化,实现绝对的霸 ...

  6. 一些斗鱼TV Web API [Some DouyuTv API]

    一些斗鱼TV Web API [Some DouyuTv API]   写在最前 去年TI5前开发了dotaonly.com,网站需要用到各个直播平台API.不像国外网站Twitch那样开放,都有现成 ...

  7. numpy数组用法大全

    机器学习的最基础模块就是numpy模块了,而numpy模块中的数组操作又是重中之重,所以我们要把数组的各种方法弄得明明白白的,以下就是数组的一些常用方法 1.创建各种各样的数组: import num ...

  8. unity独立游戏开发日志2018/09/22

    f::很头痛之前rm做的游戏在新电脑工程打不开了...只能另起炉灶... 还不知道新游戏叫什么名...暂且叫方块世界.(素材已经授权) 首先是规划下场景和素材文件夹的建立. unity常用的文件夹有: ...

  9. BGP(边界网关协议)简述

    BGP的起源 不同自治系统(路由域)间路由交换与管理的需求推动了EGP的发展,但是EGP的算法简单,无法选路,从而被BGP取代. 自治系统:(AS) IGP:自治系统内部协议,ospf,rip,is- ...

  10. 导入execl到数据库mysql

    GwykhrenyuankuList <body jwcid="$content$"> <span jwcid="@components/AppBord ...