描述 地震已经破坏了农夫约翰所有的农场以及所有连接农场的道路.作为一个意志坚强的人,他决定重建所有的农场.在重建全部N(1 <= N <= 400)个农场之前,首先必须把所有农场用道路连接起来,即任意两个农场之间必须有至少一条通路. 在研究了地图之后,农夫约翰已经得出了结论:M(1 <= M <= 10,000)条双向的道路可以在较短的时间内建造好.由于约翰的资金有限,他想以尽可能便宜的方法完成工程. 碰巧,农场里的奶牛们组建了一个专门从事重新改造在地震中被破坏的农场道路的工程公司…
传送门 01分数规划经典题. 不过用krsukal会T掉. 这题用prim反而更快(毕竟是完全图) 因此直接二分+最小生成树搞定. 代码: #include<iostream> #include<cctype> #include<cmath> #include<algorithm> #include<cstring> #include<cstdio> #define N 1005 using namespace std; double…
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…
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…
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…
题目大意:给定一个 N 个点的无向完全图,边有两个不同性质的边权,求该无向图的一棵最优比例生成树,使得性质为 A 的边权和比性质为 B 的边权和最小. 题解:要求的答案可以看成是 0-1 分数规划问题,即:选定一个数 mid,每次重新构建边权为 \(a[i]-mid*b[i]\) 的图,再在图上跑一遍最小生成树(这里由于是完全图,应该采用 Prim 算法)判断最小值和给定判定的最小值的关系即可,这里为:若最小值大于 mid,则下界提高,否则上界下降. 代码如下 #include<cmath>…
题目链接 \(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 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…
题目 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…