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…
题目描述: 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…
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…
思路:设sum(cost[i])/sum(dis[i])=r;那么要使r最小,也就是minsum(cost[i]-r*dis[i]);那么就以cost[i]-r*dis[i]为边权重新建边.当求和使得最小生成树的 sum(cost[i]-r*dis[i])==0时,这个r就是最优的.这个证明是01分数规划. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #i…
题目链接:http://poj.org/problem?id=3621 思路:之前做过最小比率生成树,也是属于0/1整数划分问题,这次碰到这道最优比率环,很是熟悉,可惜精度没控制好,要不就是wa,要不就是tle,郁闷啊!实在是懒得码字,直接copy吧: 题目的意思是:求一个环的{点权和}除以{边权和},使得那个环在所有环中{点权和}除以{边权和}最大.令在一个环里,点权为v[i],对应的边权为e[i], 即要求:∑(i=1,n)v[i]/∑(i=1,n)e[i]最大的环(n为环的点数), 设题目…
最优比率环问题.二分答案,对于每一个mid,把节点的happy值归类到边上. 对于每条边,用mid×weight减去happy值,如果不存在负环,说明还可以更大. /*--------------------------------------------------------------------------------------*/ // Helica's header // Second Edition // 2015.11.7 // #include <algorithm> #i…
Sightseeing Cows Farmer John has decided to reward his cows for their hard work by taking them on a tour of the big city! The cows must decide how best to spend their free time. Fortunately, they have a detailed city map showing the L (2 ≤ L ≤ 1000)…
题意:      让你求出一个最优比率生成环. 思路:      又是一个01分化基础题目,直接在jude的时候找出一个sigma(d[i] * x[i])大于等于0的环就行了,我是用SPFA跑最长路判断的环,这里注意一点就是刚开始的时候吧每个点都入队,还有提醒一个盲区,就是有的人认为SPFA处理不了等于0的环,其实我们不用担心这个问题,因为最外层我们用的是二分,二分永远是找接近值,就算有等于0的时候,spfa虽然找不到0.0000000 但是他可以找到0.0000000123 保留两位不还是0…
/* 迭代法 :204Ms */ #include<stdio.h> #include<string.h> #include<math.h> #define N 1100 #define eps 1e-10 #define inf 0x3fffffff struct node { int u,v,w; }p[N]; double ma[N][N]; double distance(int i,int j) { return sqrt(1.0*(p[i].u-p[j].u…
http://172.20.6.3/Problem_Show.asp?id=1636 复习了prim,分数规划大概就是把一个求最小值或最大值的分式移项变成一个可二分求解的式子. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #include<cstdlib> using namespace std; ;…
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…
http://poj.org/problem?id=2728 题意: 在这么一个图中求一棵生成树,这棵树的单位长度的花费最小是多少? 思路: 最优比率生成树,也就是01分数规划,二分答案即可,题目很简单,因为这题是稠密图,所以用prim算法会好点. #include<iostream> #include<algorithm> #include<cstring> #include<cstdio> #include<vector> #include&…
[题意]每条路径有一个 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) &…
题意:有n个村庄,村庄在不同坐标和海拔,现在要对所有村庄供水,只要两个村庄之间有一条路即可,建造水管距离为坐标之间的欧几里德距离,费用为海拔之差,现在要求方案使得费用与距离的比值最小,很显然,这个题目是要求一棵最优比率生成树. 析:也就是求 r = sigma(x[i] * d) / sigma(x[i] * dist)这个值最小,变形一下就可以得到 d * r - dist <= 0,当r 最小时,取到等号,也就是求最大生成树,然后进行判断,有两种方法,一种是二分,这个题时间长一点,另一种是迭…
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…
引用别人的解释: 题意:有n个村庄,村庄在不同坐标和海拔,现在要对所有村庄供水,只要两个村庄之间有一条路即可, 建造水管距离为坐标之间的欧几里德距离(好象是叫欧几里德距离吧),费用为海拔之差 现在要求方案使得费用与距离的比值最小 很显然,这个题目是要求一棵最优比率生成树, 概念 有带权图G, 对于图中每条边e[i], 都有benifit[i](收入)和cost[i](花费), 我们要求的是一棵生成树T, 它使得 ∑(benifit[i]) / ∑(cost[i]), i∈T 最大(或最小). 这…
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…
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…
题目链接: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…
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…
含[最小生成树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…
最优比率生成树教程见http://blog.csdn.net/sdj222555/article/details/7490797 个人觉得很明白易懂,但他写的代码略囧. 模板题,但是必须Prim,不能用Kruscal,因为是完全图 Code: #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> using namespace std; ]; int n; ]; ][],…
                                                                                                Desert King Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 25729   Accepted: 7143 Description David the Great has just become the king of a…
题意 n个点完全图,每个边有两个权值,求分数规划要求的东西的最小值. (n<=1000) 题解 心态炸了. 堆优化primT了. 普通的就过了. 我再也不写prim了!!!! 咳咳 最优比率生成树板子题. 公式不是很难推吧. #include<iostream> #include<cmath> #include<iomanip> #include<string.h> ; const int inf=0x7fffffff; using namespace…
http://poj.org/problem?id=3621 题意:有n个点m条有向边,每个点有一个点权val[i],边有边权w(i, j).找一个环使得Σ(val) / Σ(w)最大,并输出. 思路:和之前的最优比率生成树类似,还是构造成这样的式子:F(L) = Σ(val[i] * x[i]) - Σ(w[i] * x[i] * L) = Σ(d[i]) * x[i] (d[i] = val[i] - w[i] * L),要使得L越大越好. 那么当L越大的时候,F(L)就越小,如果F(L)大…
Desert King Time Limit: 3000MS   Memory Limit: 65536K Total Submissions:33847   Accepted: 9208 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…
题意: 给定L个点, P条边的有向图, 每个点有一个价值, 但只在第一经过获得, 每条边有一个花费, 每次经过都要付出这个花费, 在图中找出一个环, 使得价值之和/花费之和 最大 分析: 这道题其实并不是很好想, 因为价值和花费不是在同一样东西, 价值是点, 花费是边. 但回到我们要求的问题上, 我们要找出一个最优比率的环, 那么其实每个点只会经过一次, 是一个单独的环, 所以我们可以把价值也视为边的一部分. 参考这篇博客http://blog.csdn.net/gengmingrui/arti…
[poj2728]Desert King 题意 最优比率生成树. http://blog.csdn.net/ophunter_lcm/article/details/10113817 分析 Dinkelbach算法,通过迭代的思想进行参数搜索. 每一次的参数搜索,求出来的最小生成树又会生成一个更优的参数,然后用新的参数继续搜...以此类推. 为什么生成的参数会更优? 这是因为我们要最小化\(\sum C\over \sum D\),我们设答案为\({\sum C\over \sum D}<L\)…