Desert King Time Limit: 3000MS   Memory Limit: 65536K Total Submissions:29775   Accepted: 8192 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 count…
[题意]每条路径有一个 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) &…
一个完全图,每两个点之间的cost是海拔差距的绝对值,长度是平面欧式距离, 让你找到一棵生成树,使得树边的的cost的和/距离的和,比例最小 然后就是最优比例生成树,也就是01规划裸题 看这一发:http://blog.csdn.net/sdj222555/article/details/7490797 #include<stdio.h> #include<algorithm> #include<math.h> #include<queue> #includ…
题目: http://poj.org/problem?id=2728 题解: 二分比率,然后每条边边权变成w-mid*dis,用prim跑最小生成树就行 #include<cstdio> #include<algorithm> #include<cstring> #include<cmath> #define N 1005 using namespace std; int n,tot; double x[N],y[N],z[N],dis[N]; bool v…
题意 n个点完全图,每个边有两个权值,求分数规划要求的东西的最小值. (n<=1000) 题解 心态炸了. 堆优化primT了. 普通的就过了. 我再也不写prim了!!!! 咳咳 最优比率生成树板子题. 公式不是很难推吧. #include<iostream> #include<cmath> #include<iomanip> #include<string.h> ; const int inf=0x7fffffff; using namespace…
题意:给定n个点m条边,一开始这些边全都是断的,要修一些边使得n个点全部联通.修完一共可以得到F元,修一条边有成本di和时间ti,要使得 得到的钱数 / 总时间 这个比值最大. 参考资料: 红线内的内容转载自http://www.cnblogs.com/scau20110726/archive/2012/10/19/2730896.html ------------------------------------------------------------------------------…
题目:http://poj.org/problem?id=2728 第一道01分数规划题!(其实也蛮简单的) 这题也可以用迭代做(但是不会),这里用了二分: 由于比较裸,不作过多说明了. 代码如下: #include<iostream> #include<cstdio> #include<cstring> #include<cmath> #define eps 1e-6 using namespace std; int const inf=0x3f3f3f;…
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 capital village will be…
这题数据量较大.普通的求MST是会超时的. d[i]=cost[i]-ans*dis[0][i] 据此二分. 但此题用Dinkelbach迭代更好 #include<cstdio> #include<cstring> #include<cmath> #include<iostream> #include<algorithm> using namespace std; #define N 1010 double mp[N][N],c[N][N],x…
[POJ2728]Desert King(分数规划) 题面 vjudge 翻译: 有\(n\)个点,每个点有一个坐标和高度 两点之间的费用是高度之差的绝对值 两点之间的距离就是欧几里得距离 求一棵生成数,使得单位距离的费用最小 题解 使得\(\sum cost/\sum dis\)最小 这是分数规划问题 二分答案\(K\) 如果\(K\)满足,则有 \(\sum cost-K\sum dis\leq 0\) 定义生成树边权为\(cost-K·dis\) 做最小生成树检查答案即可. 因为是稠密图,…
http://poj.org/problem?id=2728 题意: 在这么一个图中求一棵生成树,这棵树的单位长度的花费最小是多少? 思路: 最优比率生成树,也就是01分数规划,二分答案即可,题目很简单,因为这题是稠密图,所以用prim算法会好点. #include<iostream> #include<algorithm> #include<cstring> #include<cstdio> #include<vector> #include&…
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…
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…
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 capital village will be…
Time Limit: 3000MSMemory Limit: 65536K Total Submissions: 27109Accepted: 7527 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…
http://poj.org/problem?id=2728 Desert King Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 18595   Accepted: 5245 Description David the Great has just become the king of a desert country. To win the respect of his people, he decided to b…
给出n(n<=1000)个考试的成绩ai和满分bi,要求去掉k个考试成绩,使得剩下的∑ai/∑bi*100最大并输出. 典型的01分数规划 要使∑ai/∑bi最大,不妨设ans=∑ai/∑bi,则∑ai-ans*∑bi=0. 设f[ans]=∑ai-ans*∑bi,我们要求一个ans的最大值,使得存在一组解,满足f[ans]=0,而其他的任意解都有f[ans]<=0(如果f[ans]>0,说明∑ai/∑bi>ans,即还有比ans更优的解),对于∑ai/∑bi,从0~1二分枚举答案…
引用别人的解释: 题意:有n个村庄,村庄在不同坐标和海拔,现在要对所有村庄供水,只要两个村庄之间有一条路即可, 建造水管距离为坐标之间的欧几里德距离(好象是叫欧几里德距离吧),费用为海拔之差 现在要求方案使得费用与距离的比值最小 很显然,这个题目是要求一棵最优比率生成树, 概念 有带权图G, 对于图中每条边e[i], 都有benifit[i](收入)和cost[i](花费), 我们要求的是一棵生成树T, 它使得 ∑(benifit[i]) / ∑(cost[i]), i∈T 最大(或最小). 这…
Dropping tests   Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6373   Accepted: 2198 [Description] In a certain course, you take n tests. If you get ai out of bi questions correct on test i, your cumulative average is defined to be . G…
K Best Time Limit: 8000MS   Memory Limit: 65536K Total Submissions: 12812   Accepted: 3290 Case Time Limit: 2000MS   Special Judge Description Demy has n jewels. Each of her jewels has some value vi and weight wi. Since her husband John got broke aft…
正解:01分数规划 解题报告: 传送门! 板子题鸭,,, 显然考虑变成$a[i]-mid\cdot b[i]$,显然无脑贪心下得选出最大的$k$个然后判断是否大于0就好(,,,这么弱智真的算贪心嘛$TT$ 然后就做完辣,,, 我真的$jio$得我做的题越来越水了是为什么,,,啊难过,越来越菜了可海星$TT$ #include<algorithm> #include<iomanip> #include<cstdio> using namespace std; #defin…
题意:有n组ai和bi,要求去掉k组,使下式值最大. 分析: 1.此题是典型的01分数规划. 01分数规划:给定两个数组,a[i]表示选取i的可以得到的价值,b[i]表示选取i的代价.x[i]=1代表选取i,否则x[i]=0. 求一个选择方案使得所有选择物品的总收益/总代价的值最大或是最小. 即y=Σ(a[i]*x[i])/Σ(b[i]*x[i])取得最值. 2.这类问题可以用二分解决. 最大化平均值: 设某种选取方案后得到的值为Σa[i]/Σb[i],判断此时二分到的值mid是否符合要求,若Σ…
题意: 给定n个村子的坐标(x,y)和高度z, 求出修n-1条路连通所有村子, 并且让 修路花费/修路长度 最少的值 两个村子修一条路, 修路花费 = abs(高度差), 修路长度 = 欧氏距离 分析: 01分数划分的题目, 构造出 d[i] = 修路花费 - L * 修路长度, 这个L值我们可以二分(这道题看数据范围的话二分上限其实挺大的, 但其实上限取到100就可以过), 也可以用Dinkelbach迭代出来. 二分(1422ms) #include <stdio.h> #include…
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…
题目链接 \(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://www.cnblogs.com/wally/p/3228171.html 题解请戳上面 然后对于01规划的总结 1:对于一个表,求最优比例 这种就是每个点位有benefit和cost,这样就是裸的01规划 2:对于一个树,求最优比例 这种就是每条边有benefit和cost,然后通过最小生成树来判断 3:对于一个环求最优比例 这种也是每条边有benefit和cost,然后通过spfa来判断 其实01规划最核心的地方,在于构建01规划函数,构建好函数,然后根据单调性,判断大于0或者小…
题目链接: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…
题目: http://poj.org/problem?id=3621 题解: 二分答案,检查有没有负环 #include<cstdio> #include<algorithm> #include<cstring> #define N 1005 using namespace std; struct node { int nxt,v; double w; }e[N*]; int head[N],ecnt,L,P; double dis[N],fun[N],l,r,mid;…
#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{…
题意:有n个村庄,村庄在不同坐标和海拔,现在要对所有村庄供水,只要两个村庄之间有一条路即可,建造水管距离为坐标之间的欧几里德距离,费用为海拔之差,现在要求方案使得费用与距离的比值最小,很显然,这个题目是要求一棵最优比率生成树. 析:也就是求 r = sigma(x[i] * d) / sigma(x[i] * dist)这个值最小,变形一下就可以得到 d * r - dist <= 0,当r 最小时,取到等号,也就是求最大生成树,然后进行判断,有两种方法,一种是二分,这个题时间长一点,另一种是迭…