[POI2007]POW-The Flood
题目描述
给定一张地势图,所有的点都被水淹没,现在有一些关键点,要求放最少的水泵使所有关键点的水都被抽干
输入输出格式
输入格式:
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 linedescribes the 'th row ofunitary squares in the map. It contains integers , separated by single spaces,, .
The number describes the 'th square of the ![](http://main.edu.pl/images/OI14/pow-en-tex.14.pn…
输出格式:
Your programme should write out one integer to the standard output - the minimum number of pumpsneeded to drain Byteburg.
输入输出样例
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我们首先考虑如果在格子 a 修建一个抽水机,在什么情况下格子 b 的水也可以被抽干。我们可以发现当且仅当存在一条从 a 到 b 的路径,中间经过的抽水机(包括 a)的高度都不大于 b 的高度。即h[b]>=max(h[i])因此我们可以考虑把所有格子的高度从小到大排序,我们把每一个格子建成一个集合。然后按照海拔高度从小到大扫描格子,对于当前的格子 i,我们找到所有与 i 相邻并且海拔高度不大于格子 i 的格子,我们发现如果这些格子中的任意一个洪水要是被解决了,那么格子 i 的洪水也可以被解决,所以我们合并这些格子。对于当前的格子 i,如果它必须被清理且与它相邻的格子集合中没有任何一个被清理,我们则把这个集合的清理状态标记为真,然后答案加 1。集合和每个格子是否被清理用并查集来维护就可以了。
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 using namespace std; 6 struct node 7 { 8 int s,x,y; 9 } city[1000001],maze[100001]; 10 pair<int,int> set[1001][1001]; 11 int dx[5]={0,1,-1,0,0}; 12 int dy[5]={0,0,0,1,-1}; 13 int n,m,a[1001][1001],tot,cnt,vis[1001][1001],ans; 14 bool cmp(node a,node b) 15 { 16 return (a.s<b.s); 17 } 18 pair<int,int> find(pair<int,int> x) 19 { 20 if (set[x.first][x.second]!=x) set[x.first][x.second]=find(set[x.first][x.second]); 21 return set[x.first][x.second]; 22 } 23 void union_set(pair<int,int> x,pair<int,int> y) 24 { 25 x=find(x),y=find(y); 26 set[x.first][x.second]=y; 27 vis[y.first][y.second]|=vis[x.first][x.second]; 28 } 29 void exam(int x,int y) 30 { 31 for(int i=1;i<=4;i++) 32 { 33 int tx=x+dx[i], ty=y+dy[i]; 34 if(tx<=0||ty<=0||tx>m||ty>n) continue; 35 if(a[tx][ty]>a[x][y]) continue; 36 union_set(make_pair(x, y), make_pair(tx, ty)); 37 } 38 } 39 int main() 40 { 41 int i,j; 42 cin>>n>>m; 43 for (i=1; i<=n; i++) 44 { 45 for (j=1; j<=m; j++) 46 { 47 scanf("%d",&a[i][j]); 48 if (a[i][j]<=0) 49 { 50 a[i][j]=-a[i][j]; 51 } 52 else 53 { 54 city[++tot]=(node){a[i][j],i,j}; 55 } 56 maze[++cnt]=(node){a[i][j],i,j}; 57 set[i][j]=make_pair(i,j); 58 } 59 } 60 sort(maze+1,maze+cnt+1,cmp); 61 sort(city+1,city+tot+1,cmp); 62 for (i=1; i<=tot; i++) 63 { 64 for (j=1; j<=cnt,city[i].s>=maze[j].s; j++) 65 { 66 exam(maze[j].x,maze[j].y); 67 pair<int,int> x=find(make_pair(city[i].x,city[i].y)); 68 if (vis[x.first][x.second]==0) 69 { 70 ans++; 71 vis[x.first][x.second]=1; 72 } 73 } 74 } 75 cout<<ans; 76 }
转载于:https://www.cnblogs.com/Y-E-T-I/p/7221242.html
[POI2007]POW-The Flood相关推荐
- [POI2007]洪水pow 并查集
Description 给你n*m的图,每个点有一个海拔,在较低的点放置吸水器能吸到比较高的点,有一些点是必须要吸的,问你最少需要多少吸水器. Sample Input 6 9 -2 -2 -1 -1 ...
- PyTorch 笔记(05)— Tensor 基本运算(torch.abs、torch.add、torch.clamp、torch.div、torch.mul、torch.pow等)
1. 函数汇总 Tensor 的基本运算会对 tensor 的每一个元素进行操作,此类操作的输入与输出形状一致,常用操作见下表所示. 对于很多操作,例如 div.mul.pow.fmod.等, PyT ...
- Leetcode 50. Pow(x, n)
50. Pow(x, n) Total Accepted: 96891 Total Submissions: 348858 Difficulty: Medium Implement pow(x, n) ...
- bzoj1108[POI2007]天然气管道Gaz*
bzoj1108[POI2007]天然气管道Gaz 题意: n个钻井,n个站,要求两两配对,但站必须在钻井的右下方.配一对的费用为两点的曼哈顿距离,求最小总费用.n≤50000. 题解: 发现满足条件 ...
- POW矿池挖空块原理和解决方案
第0章 引言 比特币的挖矿收益包含两部分,第一是区块奖励:第二是交易手续费.如果打空块,就收不到交易手续费,为什么有矿池会不要手续费来打空块呢? 第1章POW挖矿原理 工作量证明POW挖矿就是区块链生 ...
- DPOS机制会比POW机制表现更好吗?
共识算法一直都是区块链技术中一个核心所在,目前主流的共识算法为POW.POS.DPOS等.BCH和BCE均是采用了POW算法,今天咱们具体来类比一下DPOS和POW算法的优点缺点. DPOS机制,中文 ...
- linux测试网页装载时间,如何用Flood测试Web服务器响应时间
当你设置好服务器投入使用后,你最关心的事莫过于服务器的性能了.你可以用一些手动的方法进行测试,但手动方法有很多局限性. 先不论手工测试方法所投入的时间和精力问题,用手工方法测试的一大不足就是它不容易揭 ...
- python pow和**_Python学习笔记 | 实例3:天天向上的力量
本文为中国大学MOOC<Python语言程序设计>课程学习笔记,课程主讲:嵩天老师,练习平台:Python123,参考教材:<Python语言程序设计基础> 天天向上的力量 加 ...
- 113 - Power of Cryptography 浮点数 pow()函数
uva oj 上的一题. 113 - Power of Cryptography 就是给个 n 1<=n<=200 和 p 1<=p<10^101求个 k 1<=k< ...
最新文章
- java软件工程师成长过程的学习
- 干货 | 携程酒店MOCK全链路实践
- Vue实现仿音乐播放器2-新建Vue项目vuemusicplayer
- 【极品手机推荐】安卓3G运存16G内存,相机1300+500,三星高画质显示J7109|J7108
- AFNetworking2.0源代码解析
- C++基础::typeid、type_info
- windows server 2008r2 如何隐藏iis版本号_如何拥有自己炫酷的个人博客
- struts2 中的 addActionError 、addFieldError、addActionMessage方法的区别添加错误信息
- git拉取github上的分支和本地分支提交到github
- delphi 鼠标获取窗口句柄_pygame--创建一个简单的窗口
- 从《色戒》,看人性的欲望
- c语言中的EOF是什么意思
- 7. 模糊操作/原理/API/种类/边缘保留
- windows下sqlmap清除缓存记录
- 脚本语言、编程语言、中间件
- python高级学习笔记Day04--01 上下文管理器,生成器,深拷贝,浅拷贝,正则表达式
- Material Design设计之【色彩】实践
- 机器学习进阶 第一节 第十课
- [018]HackerRank系列 | Shell遍历某个字符串多种用法
- 武汉大学 计算机软件工程 张宇,2021年武汉理工大学计算机技术考研成功经验分享...