题目の传送门:https://www.luogu.org/problem/show?pid=1550 精简版题意(本来就精简了不是么):n个点,每个点可以选择打井或从别的有水的点引水,求所有点都有水用的最小费用.(我是不是一说反而更不懂了) 这题其实并不是很难,讲道理贪心都能过.. 令我感到有趣的是这题中一种非常神奇的解题思路.. 首先,如果这个题没有打井的选项,显然是最小生成树 然而我们现在要打井,就不能直接用最小生成树做了.. 殊不知,这题还是一个最小生成树~ 这就需要一些小小的.巧妙的办法…
P1550 [USACO08OCT]打井Watering Hole 题目背景 John的农场缺水了!!! 题目描述 Farmer John has decided to bring water to his N (1 <= N <= 300) pastures which are conveniently numbered 1..N. He may bring water to a pasture either by building a well in that pasture or con…
题面:P1550 [USACO08OCT]打井Watering Hole 题解:无 代码: #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #define ll long long using namespace std; ; ,edge_head[maxn]; ll Z,ans; *maxn*maxn]; inline void Add_edge(int f…
P1550 [USACO08OCT]打井Watering Hole   对于自己建水库的情况,新建一个虚拟结点,和其他点的边权即为自建水库的费用 这样问题就转化为一个裸最小生成树问题了. 这里用堆优化prim解决. #include<iostream> #include<cstdio> #include<cstring> #include<cctype> #include<queue> #define re register using name…
P1550 [USACO08OCT]打井Watering Hole 题目背景 John的农场缺水了!!! 题目描述 Farmer John has decided to bring water to his N (1 <= N <= 300) pastures which are conveniently numbered 1..N. He may bring water to a pasture either by building a well in that pasture or con…
为了优化体验(其实是强迫症),蒟蒻把总结拆成了两篇,方便不同学习阶段的Dalao们切换. LCT总结--应用篇戳这里 概念.性质简述 首先介绍一下链剖分的概念(感谢laofu的讲课) 链剖分,是指一类对树的边进行轻重划分的操作,这样做的目的是为了减少某些链上的修改.查询等操作的复杂度. 目前总共有三类:重链剖分,实链剖分和并不常见的长链剖分 重链剖分 实际上我们经常讲的树剖,就是重链剖分的常用称呼. 对于每个点,选择最大的子树,将这条连边划分为重边,而连向其他子树的边划分为轻边. 若干重边连接在…
题面 题目背景 John的农场缺水了!!! 题目描述 Farmer John has decided to bring water to his N (1 <= N <= 300) pastures which are conveniently numbered 1..N. He may bring water to a pasture either by building a well in that pasture or connecting the pasture via a pipe…
本题看似很难,实际上思路非常简单--如果你想通了. 首先有一个问题:图中有几个点?大部分的人会回答\(n\)个点.错了,有\(n+1\)个. 多出来的那个点在哪?关键在于你要理解每一个决策的意义.实际上,多出来的那个点是地下的天然矿泉水.当我们打井时,我们实际上是在往地下连边.理解了这一点,代码就没有任何难度了. 构图时,我们只需多加一个点,对于每个点\(i\),我们连边\(i→n+1\),边权为\(w_i\).然后直接跑最小生成树就没了.就没了.(转载from here) #include<b…
打井 题目 该题是一个最小生成树的好题,但是比起一般的最小生成树来说他不仅仅有各个井相连,而且还要和地下水相连,所以地下水我们也可以看成一口井. 代码 #include <bits/stdc++.h> using namespace std; struct edge { int a, b, c; }e[100100]; bool cmp(const edge &a, const edge &b) { return a.c < b.c; } int cnt, fa[1001…
题目背景 John的农场缺水了!!! 题目描述 Farmer John has decided to bring water to his N (1 <= N <= 300) pastures which are conveniently numbered 1..N. He may bring water to a pasture either by building a well in that pasture or connecting the pasture via a pipe to…