题目链接:http://poj.org/problem?id=2728 题目: 题意:求一颗生成树,使得费用与距离的比值最小,其中距离等于两点之间的平面欧拉距离,费用为z坐标之差. 思路: 由上图我们可以得知,我们只需对x进行二分(最大化平均值),以cost[i]-len[i]*x为边权跑prime即可. 代码实现如下: #include <set> #include <map> #include <queue> #include <stack> #incl…
POJ2728 Desert King Description David the Great has just become the king of a desert country. To win the respect of his people, he decided to build channels all over his country to bring water to every village. Villages which are connected to his cap…
Desert King http://poj.org/problem?id=2728 Time Limit: 3000MS   Memory Limit: 65536K       Description David the Great has just become the king of a desert country. To win the respect of his people, he decided to build channels all over his country t…
http://poj.org/problem?id=2728 题意: 在这么一个图中求一棵生成树,这棵树的单位长度的花费最小是多少? 思路: 最优比率生成树,也就是01分数规划,二分答案即可,题目很简单,因为这题是稠密图,所以用prim算法会好点. #include<iostream> #include<algorithm> #include<cstring> #include<cstdio> #include<vector> #include&…
含[最小生成树Prim]模板. Prim复杂度为$O(n^2),适用于稠密图,特别是完全图的最小生成树的求解.   Desert King Time Limit: 3000MS   Memory Limit: 65536K Total Submissions:31622   Accepted: 8670 Description David the Great has just become the king of a desert country. To win the respect of h…
Desert King Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 25310   Accepted: 7022 Description David the Great has just become the king of a desert country. To win the respect of his people, he decided to build channels all over his coun…
http://poj.org/problem?id=2728 题意:有n个点,有三个属性代表每个点在平面上的位置,和它的高度.点与点之间有一个花费:两点的高度差:还有一个长度:两点的距离.现在要让你在这n个点里面弄一个生成树,使得∑cost / ∑dis 最小,问最小的比率是多少. 思路:求得的比率R = ∑(cost[i] * x[i]) / ∑(dis[i] * x[i]),x[i]为1代表选这个点,转化一下,就是要minimize(R). 设F(L) = ∑(cost[i] * x[i])…
题目链接:http://poj.org/problem?id=2728 题意: 给你n个点(x,y,z),让你求一棵生成树,使得 k = ∑ |z[i]-z[j]| / ∑ dis(i,j)最小. |z[i]-z[j]|为一条边两端点的高度(z)之差,dis(i,j)为两端点在xy平面投影的欧几里得距离. 题解: 二分答案R. 如果当前的R还没有达到最小值ans,即R >= ans,则一定有一种方案使得 ∑ |z[i]-z[j]| / ∑ dis(i,j) <= R. 化简得: ∑ (|z[i…
传送门 01分数规划经典题. 不过用krsukal会T掉. 这题用prim反而更快(毕竟是完全图) 因此直接二分+最小生成树搞定. 代码: #include<iostream> #include<cctype> #include<cmath> #include<algorithm> #include<cstring> #include<cstdio> #define N 1005 using namespace std; double…
#include <iostream> #include <cstdio> #include <cmath> #include <cstdlib> #include <cstring> #include <iomanip> using namespace std; const int maxn=1005; const double eps=1e-6; const double inf=0xffffffff; struct node{…
题目描述: David the Great has just become the king of a desert country. To win the respect of his people, he decided to build channels all over his country to bring water to every village. Villages which are connected to his capital village will be water…
最优比率生成树教程见http://blog.csdn.net/sdj222555/article/details/7490797 个人觉得很明白易懂,但他写的代码略囧. 模板题,但是必须Prim,不能用Kruscal,因为是完全图 Code: #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> using namespace std; ]; int n; ]; ][],…
题意 n个点完全图,每个边有两个权值,求分数规划要求的东西的最小值. (n<=1000) 题解 心态炸了. 堆优化primT了. 普通的就过了. 我再也不写prim了!!!! 咳咳 最优比率生成树板子题. 公式不是很难推吧. #include<iostream> #include<cmath> #include<iomanip> #include<string.h> ; const int inf=0x7fffffff; using namespace…
Desert King Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 20978   Accepted: 5898 [Description] David the Great has just become the king of a desert country. To win the respect of his people, he decided to build channels all over his co…
[题意]每条路径有一个 cost 和 dist,求图中 sigma(cost) / sigma(dist) 最小的生成树. 标准的最优比率生成树,楼教主当年开场随手1YES然后把别人带错方向的题Orz-- ♦01分数规划 参考Amber-胡伯涛神牛的论文<最小割模型在信息学竞赛中的应用> °定义 分数规划(fractional programming)的一般形式: Minimize  λ = f(x) = a(x) / b(x)   ( x∈S  && ∀x∈S, b(x) &…
01分数规划 前置技能 二分思想最短路算法一些数学脑细胞? 问题模型1 基本01分数规划问题 给定nn个二元组(valuei,costi)(valuei,costi),valueivaluei是选择此二元组获得的价值(非负),costicosti是选择此二元组付出的代价(非负),设xi(xi∈{0,1})xi(xi∈{0,1})代表第ii个二元组的选与不选,最大(小)化下式 maximize(or minimize)   r=∑valuei⋅xi∑costi⋅ximaximize(or mini…
Desert King Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 28407   Accepted: 7863 Description David the Great has just become the king of a desert country. To win the respect of his people, he decided to build channels all over his coun…
题面:[USACO 2001 OPEN]地震 题目描述: 一场地震把约翰家的牧场摧毁了, 坚强的约翰决心重建家园. 约翰已经重建了N个牧场,现在他希望能修建一些道路把它们连接起来.研究地形之后,约翰发现可供修建的道路有M条.碰巧的是,奶牛们最近也成立一个工程队,专门从事修复道路.而然,奶牛们很有经济头脑,如果无利可图,它们是不会干的. 奶牛们关注的是挣钱速度,即总利润和总施工时间的比值.约翰和奶牛达成了协议,奶牛负责修建道路,将所有牧场连通,而约翰需要支付F元.每条道路都有自己的施工时间和建造成…
描述 地震已经破坏了农夫约翰所有的农场以及所有连接农场的道路.作为一个意志坚强的人,他决定重建所有的农场.在重建全部N(1 <= N <= 400)个农场之前,首先必须把所有农场用道路连接起来,即任意两个农场之间必须有至少一条通路. 在研究了地图之后,农夫约翰已经得出了结论:M(1 <= M <= 10,000)条双向的道路可以在较短的时间内建造好.由于约翰的资金有限,他想以尽可能便宜的方法完成工程. 碰巧,农场里的奶牛们组建了一个专门从事重新改造在地震中被破坏的农场道路的工程公司…
题目大意:给定一个 N 个点的无向完全图,边有两个不同性质的边权,求该无向图的一棵最优比例生成树,使得性质为 A 的边权和比性质为 B 的边权和最小. 题解:要求的答案可以看成是 0-1 分数规划问题,即:选定一个数 mid,每次重新构建边权为 \(a[i]-mid*b[i]\) 的图,再在图上跑一遍最小生成树(这里由于是完全图,应该采用 Prim 算法)判断最小值和给定判定的最小值的关系即可,这里为:若最小值大于 mid,则下界提高,否则上界下降. 代码如下 #include<cmath>…
题目链接:http://poj.org/problem?id=2728 Desert King Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 26878   Accepted: 7459 Description David the Great has just become the king of a desert country. To win the respect of his people, he decided…
Desert King Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 22717   Accepted: 6374 Description David the Great has just become the king of a desert country. To win the respect of his people, he decided to build channels all over his coun…
一个完全图,每两个点之间的cost是海拔差距的绝对值,长度是平面欧式距离, 让你找到一棵生成树,使得树边的的cost的和/距离的和,比例最小 然后就是最优比例生成树,也就是01规划裸题 看这一发:http://blog.csdn.net/sdj222555/article/details/7490797 #include<stdio.h> #include<algorithm> #include<math.h> #include<queue> #includ…
Language: Default Desert King Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 22113   Accepted: 6187 Description David the Great has just become the king of a desert country. To win the respect of his people, he decided to build channels…
                                                                                                Desert King Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 25729   Accepted: 7143 Description David the Great has just become the king of a…
题目链接 \(Description\) 将n个村庄连成一棵树,村之间的距离为两村的欧几里得距离,村之间的花费为海拔z的差,求花费和与长度和的最小比值 \(Solution\) 二分,假设mid为可行的某一生成树的解,则应有 \((∑cost)/(∑dis) = mid\) 变形得 \(\sum(cost-mid*dis) = 0\) 取cost-mid*dis为边权,Prim求最小生成树(即尽可能满足mid) 若\(\sum(cost-mid*dis) > 0\),说明怎么也满足不了mid,m…
题目 http://poj.org/problem?id=2728 关键词:0/1分数规划,参数搜索,二分法,dinkelbach 参考资料:http://hi.baidu.com/zzningxp/item/28aa46e0fd86bdc2bbf37d03 http://hi.baidu.com/zheng6822/item/b31fbe9d5ae17536336eeb8f #include<stdio.h> #include<string.h> #include<iost…
题意: 给定n个村子的坐标(x,y)和高度z, 求出修n-1条路连通所有村子, 并且让 修路花费/修路长度 最少的值 两个村子修一条路, 修路花费 = abs(高度差), 修路长度 = 欧氏距离 分析: 01分数划分的题目, 构造出 d[i] = 修路花费 - L * 修路长度, 这个L值我们可以二分(这道题看数据范围的话二分上限其实挺大的, 但其实上限取到100就可以过), 也可以用Dinkelbach迭代出来. 二分(1422ms) #include <stdio.h> #include…
David the Great has just become the king of a desert country. To win the respect of his people, he decided to build channels all over his country to bring water to every village. Villages which are connected to his capital village will be watered. As…
别人解题报告的链接: http://blog.sina.com.cn/s/blog_691190870101626q.html 说明一下关于精度的问题,当结果是精确到小数点后3为,你自然要把误差定为至少10^(-4),我定的是10^(-8)````这里多定点没事的··· 然后对于POJ上的提交,如果是用C++提交,可以写printf("%.3lf\n",ans); 但是如果是用的G++提交,就得用printf("%.3f\n",ans); 当然ans定义的是doub…