luogu P1550 [USACO08OCT]打井Watering Hole】的更多相关文章

题面: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…
题目背景 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…
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…
题面 题目背景 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…
题目描述 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 another pasture whi…
本题看似很难,实际上思路非常简单--如果你想通了. 首先有一个问题:图中有几个点?大部分的人会回答\(n\)个点.错了,有\(n+1\)个. 多出来的那个点在哪?关键在于你要理解每一个决策的意义.实际上,多出来的那个点是地下的天然矿泉水.当我们打井时,我们实际上是在往地下连边.理解了这一点,代码就没有任何难度了. 构图时,我们只需多加一个点,对于每个点\(i\),我们连边\(i→n+1\),边权为\(w_i\).然后直接跑最小生成树就没了.就没了.(转载from here) #include<b…
题面(翻译有点问题,最后一句话) 农民John 决定将水引入到他的n(1<=n<=300)个牧场.他准备通过挖若 干井,并在各块田中修筑水道来连通各块田地以供水.在第i 号田中挖一口井需要花费W_i(1<=W_i<=100,000)元.连接i 号田与j 号田需要P_ij (1 <= P_ij <= 100,000 , P_ji=P_ij)元. 请求出农民John 需要为使所有农场都与有水的农场相连或拥有水井所需要的钱数. 题意 有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…
题意:有N个牧场,每个牧场修水井花费Wi,连接牧场花费Pij,问最小花费,使得每个牧场要么有水井,要么和有水井的牧场有通道. 思路:加一个格外的节点O,连接O表示修井,边权是修井的费用.     那么这N+1个点求最MST即可. 刘同学想到的解法: 先找到修井费用最低的的牧场,然后和上面一样,由于最低的那个必选,所以异曲同工. #include<bits/stdc++.h> #define rep(i,a,b) for(int i=a;i<=b;i++) using namespace…