P1550打井】的更多相关文章

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…
打井 题目 该题是一个最小生成树的好题,但是比起一般的最小生成树来说他不仅仅有各个井相连,而且还要和地下水相连,所以地下水我们也可以看成一口井. 代码 #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…
这是USACO2008年的一道最小生成树题,感谢dzj老师那天教的图论. 要引渠让每一个村庄都可以接到水,然后从某一个村庄到另一个村庄修剪水道要花费w元,并且还要打井(至少一个)(而输入数据也包括了在每一个村庄打井的费用),需要为使所有农场都与有水的村庄相连或拥有水井所需要的钱数.很明显,这个题只有建成一个联通的图,然后求最小权值和即可.所以我选用了kruskal算法求最小生成树.但是这里还有一个问题,就是怎么判断是打井还是连水道的问题.那么我们则用到了“超级元”的思想,让水井代表0号节点,则边…
题面: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…
题面 题目背景 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…
题目背景 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…
本题看似很难,实际上思路非常简单--如果你想通了. 首先有一个问题:图中有几个点?大部分的人会回答\(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个点,每个点之间都有边权,但是每个点也…