POJ 3621 最优比率生成环】的更多相关文章

题意:      让你求出一个最优比率生成环. 思路:      又是一个01分化基础题目,直接在jude的时候找出一个sigma(d[i] * x[i])大于等于0的环就行了,我是用SPFA跑最长路判断的环,这里注意一点就是刚开始的时候吧每个点都入队,还有提醒一个盲区,就是有的人认为SPFA处理不了等于0的环,其实我们不用担心这个问题,因为最外层我们用的是二分,二分永远是找接近值,就算有等于0的时候,spfa虽然找不到0.0000000 但是他可以找到0.0000000123 保留两位不还是0…
/* 和求最小生成树差不多 转载思路:http://www.cnblogs.com/wally/p/3228171.html 思路:之前做过最小比率生成树,也是属于0/1整数划分问题,这次碰到这道最优比率环,很是熟悉,可惜精度没控制好,要不就是wa,要不就是tle,郁闷啊!实在是懒得码字,直接copy吧: 题目的意思是:求一个环的{点权和}除以{边权和},使得那个环在所有环中{点权和}除以{边权和}最大. 令在一个环里,点权为v[i],对应的边权为e[i], 即要求:∑(i=1,n)v[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为环的点数), 设题目…
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)…
思路:以val[u]-ans*edge[i].len最为边权,判断是否有正环存在,若有,那么就是ans小了.否则就是大了. 在spfa判环时,先将所有点进队列. #include<iostream> #include<cstdio> #include<queue> #include<cstring> #include<algorithm> #include<cmath> #define Maxn 1010 #define Maxm 6…
最优比率环问题.二分答案,对于每一个mid,把节点的happy值归类到边上. 对于每条边,用mid×weight减去happy值,如果不存在负环,说明还可以更大. /*--------------------------------------------------------------------------------------*/ // Helica's header // Second Edition // 2015.11.7 // #include <algorithm> #i…
http://poj.org/problem?id=3621 Sightseeing Cows Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7649   Accepted: 2567 Description Farmer John has decided to reward his cows for their hard work by taking them on a tour of the big city! Th…
思路:设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…
Sightseeing Cows Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8218   Accepted: 2756 Description 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…
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…
[题意]每条路径有一个 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分数规划的基本裸题. 因为路线一定是个环,所以找个最优比率生成环即可 二分一个比值,check一下即可. #include <queue> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int N=1005; int l,p,a[1005],inq[1005],cnt[1005],head[1005],ecnt; struct Ed…
Sightseeing Cows Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10306   Accepted: 3519 Description 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…
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)大…
题意: 给定L个点, P条边的有向图, 每个点有一个价值, 但只在第一经过获得, 每条边有一个花费, 每次经过都要付出这个花费, 在图中找出一个环, 使得价值之和/花费之和 最大 分析: 这道题其实并不是很好想, 因为价值和花费不是在同一样东西, 价值是点, 花费是边. 但回到我们要求的问题上, 我们要找出一个最优比率的环, 那么其实每个点只会经过一次, 是一个单独的环, 所以我们可以把价值也视为边的一部分. 参考这篇博客http://blog.csdn.net/gengmingrui/arti…
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…
题意:有n个村庄,村庄在不同坐标和海拔,现在要对所有村庄供水,只要两个村庄之间有一条路即可,建造水管距离为坐标之间的欧几里德距离,费用为海拔之差,现在要求方案使得费用与距离的比值最小,很显然,这个题目是要求一棵最优比率生成树. 析:也就是求 r = sigma(x[i] * d) / sigma(x[i] * dist)这个值最小,变形一下就可以得到 d * r - dist <= 0,当r 最小时,取到等号,也就是求最大生成树,然后进行判断,有两种方法,一种是二分,这个题时间长一点,另一种是迭…
[题目链接] http://poj.org/problem?id=3621 [算法] 01分数规划(最优比率环) [代码] #include <algorithm> #include <bitset> #include <cctype> #include <cerrno> #include <clocale> #include <cmath> #include <complex> #include <cstdio&g…
Sightseeing Cows Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8915   Accepted: 3000 Description 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…
题面:[USACO 2001 OPEN]地震 题目描述: 一场地震把约翰家的牧场摧毁了, 坚强的约翰决心重建家园. 约翰已经重建了N个牧场,现在他希望能修建一些道路把它们连接起来.研究地形之后,约翰发现可供修建的道路有M条.碰巧的是,奶牛们最近也成立一个工程队,专门从事修复道路.而然,奶牛们很有经济头脑,如果无利可图,它们是不会干的. 奶牛们关注的是挣钱速度,即总利润和总施工时间的比值.约翰和奶牛达成了协议,奶牛负责修建道路,将所有牧场连通,而约翰需要支付F元.每条道路都有自己的施工时间和建造成…
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…
描述 地震已经破坏了农夫约翰所有的农场以及所有连接农场的道路.作为一个意志坚强的人,他决定重建所有的农场.在重建全部N(1 <= N <= 400)个农场之前,首先必须把所有农场用道路连接起来,即任意两个农场之间必须有至少一条通路. 在研究了地图之后,农夫约翰已经得出了结论:M(1 <= M <= 10,000)条双向的道路可以在较短的时间内建造好.由于约翰的资金有限,他想以尽可能便宜的方法完成工程. 碰巧,农场里的奶牛们组建了一个专门从事重新改造在地震中被破坏的农场道路的工程公司…
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…
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…
题意: 给定n个点,每个点有一个开心度F[i],每个点有m条单向边,每条边有一个长度d,要求一个环,使得它的 开心度的和/长度和 这个比值最大.n<=1000,m<=5000 题解: 最优比率环,很像以前做过的一题最优比率生成树.首先二分一个答案r=sigma(xi*fi)/sigma(xi*di),设z=r*sigma(xi*di)-sigma(xi*fi),若能找到一个环满足z<=0,则代表sigma(xi*fi)>=r*sigma(xi*di),则r可以比当前的r要大,则l=…
最优比率生成树教程见http://blog.csdn.net/sdj222555/article/details/7490797 个人觉得很明白易懂,但他写的代码略囧. 模板题,但是必须Prim,不能用Kruscal,因为是完全图 Code: #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> using namespace std; ]; int n; ]; ][],…
题目链接:http://poj.org/problem?id=3621 Sightseeing Cows Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11526   Accepted: 3930 Description Farmer John has decided to reward his cows for their hard work by taking them on a tour of the big ci…
题目描述: 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…