Transfer water Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others)Total Submission(s): 3995    Accepted Submission(s): 1438 Problem Description XiaoA lives in a village. Last year flood rained the village. So they deci…
Transfer water Time Limit:3000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 4009 Description XiaoA lives in a village. Last year flood rained the village. So they decide to move the whole village to the moun…
HDU - 4009:http://acm.hdu.edu.cn/showproblem.php?pid=4009 题意: 有n户人家住在山上,现在每户人家(x,y,z)都要解决供水的问题,他可以自己挖井,也可以从特定的别人那里调水.问所有人家都接上水后最小的花费. 思路: 据说是一道最小生成树的模版题,我觉得在建图上还是比较难的.每个人家从别人那里调水的关系是明确的,直接建图就行.那自己挖井,我们可以建立一个虚拟的源点,向每个点连一条边,边的权值就是挖井所要的费用.建完图后,就可以跑一遍最小树…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4009 题意:给出一个村庄(x,y,z).每个村庄可以挖井或者修建水渠从其他村庄得到水.挖井有一个代价,修水渠有一个代价.另外A村庄只能向其指定的一些村庄供水.使得所有村庄有水求最小代价. 思路,建立源节点0,向每个点连边视为挖井,如果从其他村庄得到水就相当于从那个点引一条有向边过来. #include<algorithm> #include<cstdio> #include<cm…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4009 题意:给出一个村庄(x,y,z).每个村庄可以挖井或者修建水渠从其他村庄得到水.挖井有一个代价,修水渠有一个代价.另外A村庄只能向其指定的一些村庄供水.使得所有村庄有水求最小代价. 思路:增加虚拟点0,向所有点连边表示挖井.能连边的连边.求最小树形图即可. struct point { int x,y,z; }; struct edge { int u,v,w; }; point p[N];…
分析:建一个远点,往每个点连建井的价值(单向边),其它输水线按照题意建单向边 然后以源点为根的权值最小的有向树就是答案,套最小树形图模板 #include <iostream> #include <algorithm> #include <cstdio> #include <cstdlib> #include <cstring> #include <string> #include <stack> #include <…
Transfer water Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others) Total Submission(s): 4216    Accepted Submission(s): 1499 Problem Description XiaoA lives in a village. Last year flood rained the village. So they dec…
Transfer water Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others)Total Submission(s): 6126    Accepted Submission(s): 2181 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4009 Description: XiaoA lives in a village. Las…
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-size: 10.5000pt } h1 { margin-top: 5.0000pt; margin-bottom: 5.0000pt; text-align: center; font-family: 宋体; color: rgb(26,92,200); font-weight: bold; fo…
hdu 2121 题目:给出m条有向路,根不确定,求一棵最小的有向生成树. 分析:增加一个虚拟节点,连向n个节点,费用为inf(至少比sigma(cost_edge)大).以该虚拟节点为根求一遍最小树形图算法,这时肯定存在解,如果费用>=inf时,说明无解.这是因为sigma(cost_edge)<inf.如何求得根?在寻找前驱时发现为根,则更新一下那条边的边号即可. hdu 4009 题目:n个地方需要供水,可以自己挖水井供给自己,或者可以从别的地方供水,给出各自的方案,问对n个城市供水的最…
题目链接:https://vjudge.net/problem/HDU-4009 Transfer water Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others)Total Submission(s): 5612    Accepted Submission(s): 1997 Problem Description XiaoA lives in a village. Last ye…
Transfer water Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others) Total Submission(s): 3775    Accepted Submission(s): 1356 Problem Description XiaoA lives in a village. Last year flood rained the village. So they dec…
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5443 The Water Problem Description In Land waterless, water is a very limited resource. People always fight for the biggest source of water. Given a sequence of water sources with $a_1, a_2, a_3, . . . ,…
A water problem 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5832 Description Two planets named Haha and Xixi in the universe and they were created with the universe beginning. There is 73 days in Xixi a year and 137 days in Haha a year. Now you k…
The Water Problem Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5443 Description In Land waterless, water is a very limited resource. People always fight for the biggest source of water. Given a sequence of wat…
A water problem 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5832 Description Two planets named Haha and Xixi in the universe and they were created with the universe beginning. There is 73 days in Xixi a year and 137 days in Haha a year. Now you k…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5443 The Water Problem Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 1084    Accepted Submission(s): 863 Problem Description In Land waterless…
题目链接:HDU 5443 Problem Description In Land waterless, water is a very limited resource. People always fight for the biggest source of water. Given a sequence of water sources with \(a_1,a_2,a_3,...,a_n\) representing the size of the water source. Give…
A water problem Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 595    Accepted Submission(s): 308 Problem Description Two planets named Haha and Xixi in the universe and they were created with…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5443 题目大意: T组数据.n个值,m个询问,求区间l到r里的最大值.(n,m<=1000) 题目思路: [线段树] 线段树裸题.求区间最大值. // //by coolxxx // #include<iostream> #include<algorithm> #include<string> #include<iomanip> #include<…
Problem Description In Land waterless, water is a very limited resource. People always fight for the biggest source of water. Given a sequence of water sources with a1,a2,a3,...,an representing the size of the water source. Given a set of queries eac…
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4183 这题题目意思非常难看懂..我看了好长时间也没看懂..终于是从网上找的翻译. .我就在这翻译一下吧. 意思大约是:有多个点,每一个点给出坐标与半径,增加两个点相交,就能够从这两个点走.题目要求先从起点到终点,再从终点回到起点.从起点到终点的过程中.仅仅能从频率小的走到频率大的点(前提是两点相交).从终点到起点的过程中.仅仅能从频率大的走到频率小的.在走的过程中,除了起点与终点,别的仅仅要走过就会…
题意:给定 n 个数,然后有 q 个询问,问你每个区间的最大值. 析:数据很小,直接暴力即可,不会超时,也可以用RMQ算法. 代码如下: #include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include <iostream> #include <cstring> #include <set> #include <queue…
题意:给定一个大数,问你取模73 和 137是不是都是0. 析:没什么可说的,先用char 存储下来,再一位一位的算就好了. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include <iostream>…
思路:唯一一个值得一提的就是建一个0号根节点,往每个房子建一条边,权值为房子的高度乘以X. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #define Maxn 1010 #define Maxm Maxn*Maxn #define inf 100000000 using namespace std; int h…
讲一下建图过程,首先建立一个超级源点S,对于这个源点,向每个HOUSE连一条有向边,权值为该HOUSE建立WELL的费用,即高度*X. 然后每个可以连边的WELL之间,费用为曼哈顿距离*Y,然后考虑两边的高度,如果需要连接PUMB,则在该费用上+Z. 这样建图之后,以S为根,跑一遍最小树形图算法即可. CODE: #include <set> #include <map> #include <stack> #include <cmath> #include…
https://vjudge.net/problem/HDU-5575 题意: 有一个水箱,被n-1块板子分成了n个部分,板子的高度不尽相同.现在有m次探测,每次探测在第x部分的y+0.5高度处是否有水,回答0代表没水,1代表有水.现在要求出这m次探测最多有多少次是正确的. 思路: 挺难的一道题目吧. 一开始如果把水箱当成空的,那么所有的无水探测就都是真的,至于有水探测的话,接下来我们可以一点一点的加水,这就要求将有水探测排序.每个部分可能会有多个无水探测(比如在第1部分,它进高度为1.3.5的…
题意: 有一个水槽,边界的两块板是无穷高的,中间有n-1块隔板(有高度),现有一些条件(i,y,k),表示从左到右数的第i列中,在高度为(y+0.5)的地方是否有水(有水:k = 1),问最多能同时满足多少个条件.范围:1e5 分析: 考虑按隔板的高度从小到大合并隔板相邻的两列,合并的时候新开一个节点,这个可以用并查集来做. 这样合并过来就会得到一棵树,接下来就考虑如何把询问塞进去,然后做树形DP. 对于一个询问,我们需要把它存入第i列对应的叶节点上的某个父亲那里去,这个可以用vector来做,…
#include<stdio.h> /*思路:显然对于每个地方, 只有一种供水方式就足够了,这样也能保证花费最小, 而每个地方都可以自己挖井,所以是不可能出现无解的情况的, 为了方便思考,我们引入一个虚拟点,把所有自己挖井的都连到这个点, 边权为挖井的花费,而如果i能从j处引水,则从j向i连边,边权为引水的花费, 然后对这个有向图,以虚拟点为根,求最小树形图即可(最小树形图即为有向图的最小生成树).*/ #include<string.h> #include<math.h&g…
每一户人家水的来源有两种打井和从别家接水,每户人家都可能向外输送水. 打井和接水两种的付出代价都接边.设一个超级源点,每家每户打井的代价就是从该点(0)到该户人家(1~n)的边的权值.接水有两种可能,从高处接水,那么代价是哈密顿距离与Y的乘积(可以认为就是水管的费用):从低处接水,还要加上付出水泵的钱(水管+水泵的费用).这样就可以建图了.图论,会建图的话问题就解决一半了. 然后,用模版来解题.不过朱刘算法的模版时间复杂度的差异还是蛮大的.我的模版的建图是邻接矩阵,时间复杂度是O(N^3).超时…