POJ3621:Sightseeing Cows——题解】的更多相关文章

题目链接:http://poj.org/problem?id=3621 Sightseeing Cows Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10552   Accepted: 3613 Description Farmer John has decided to reward his cows for their hard work by taking them on a tour of the big ci…
http://poj.org/problem?id=3621 全文翻译参自洛谷:https://www.luogu.org/problemnew/show/P2868 题目大意:一个有向图,每个点都有一个价值,每条路通过需要一定时间,求出一个回路使得价值和/时间和最大.(重复经过一个点不会额外增加价值) 按照01分数规划的套路,我们显然可以将路的边权更改为时间*枚举的答案-目的地价值,然后找一个环. 如果这个环是一个负环,那么显然答案还可以变得更大,反之则需要变小. 所以我们需要用spfa判断图…
题目链接:id=3621">http://poj.org/problem?id=3621 在一个有向图中选一个环,使得环上的点权和除以边权和最大.求这个比值. 经典的分数规划问题,我认为这两篇题解写得非常清楚,能够參考一下http://blog.csdn.net/gengmingrui/article/details/47443705,http://blog.csdn.net/wall_f/article/details/8221807 个人认为01分数规划差点儿都是二分或者迭代比值,从而…
典型的求最优比例环问题 參考资料: http://blog.csdn.net/hhaile/article/details/8883652 此题中,给出每一个点和每条边的权值,求一个环使 ans=∑点权/∑边权 最大. 由于题目要求一个环,并且必定是首尾相接的一个我们理解的纯粹的环,不可能是其它样子的环, 所以我们能够把一条边和指向的点看做总体处理. 上面方程能够化为:ans×e[i]-p[i]=0 以它为边权二分答案,spfa求负环,有负环则该ans可行,增大下界. 若一直不可行,则无解. #…
题目大意:在一个无向图里找一个环,是的点权和除以边权和最大 思路:UVA11090姊妹题 事实上当这题点权和都为1时就是上一题TUT #include <stdio.h> #include <iostream> #include<queue> #include <string.h> #include <algorithm> #define maxn 10009 #define maxm 10001 #define esp 0.001 using…
01分数规划 二分+spfa负环(SLF优化) #include<cstdio> #include<iostream> #include<cstring> #include<cstdlib> #include<algorithm> #include<cmath> using namespace std; int n,m; ]; ]; struct node { int x,y,next;double d; }a[];]; void i…
题面 这道题是一道标准的01分数规划: 但是有一些细节可以优化: 不难想到要二分一个mid然后判定图上是否存在一个环S,该环是否满足∑i=1t(Fun[vi]−mid∗Tim[ei])>0 但是上面的算法并不好实现,所以可以将两边同时乘上-1,使式子变为∑i=1t​(mid∗Tim[ei​]−Fun[vi​])<0 那么该问题就转化成了在每一个图中跑一边SPFA来寻找是否存在负环,若存在则l=mid,否则r=mid: #include <bits/stdc++.h> #define…
[POJ3621]Sightseeing Cows 题意:在给定的一个图上寻找一个环路,使得总欢乐值(经过的点权值之和)/ 总时间(经过的边权值之和)最大. 题解:显然是分数规划,二分答案ans,将每条边的权值变成(ans*边权-2*起始点点权),然后我们希望找出一个环,使得环上的总边权<0 (一开始我把题意理解错了,题中给的是单向边,我把它当成是双向边+每条边只能走一次了~,想出一堆做法都接连pass掉) 然后就直接用SPFA判负环就好了嘛!由于原图不一定联通,所以一开始就把所有点都入队就完事…
[POJ3621][洛谷2868]Sightseeing Cows(分数规划) 题面 Vjudge 洛谷 大意: 在有向图图中选出一个环,使得这个环的点权\(/\)边权最大 题解 分数规划 二分答案之后把每条边的边权换为\(mid·\)边权-出点的点权 然后检查有没有负环就行啦 #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath&g…
Sightseeing Cows Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8331   Accepted: 2791 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…
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…
P2868 [USACO07DEC]观光奶牛Sightseeing Cows [](https://www.cnblogs.com/images/cnblogs_com/Tony-Double-Sky/1270353/o_YH[_INPMKE_4RY]3DF(33@G.png) 错误日志: dfs 判负环没有把初值赋为 \(0\) 而是 \(INF\), 速度变慢 Solution 设现在走到了一个环, 环内有 \(n\) 个点, \(n\) 条边, 点权为 \(f_{i}\), 边权为 \(e…
题目链接: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…
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…
P2868 [USACO07DEC]观光奶牛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 sh…
[USACO07DEC]Sightseeing Cows 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 spend their free time. Fortunately, they have a detailed city map showi…
Sightseeing Cows 给出一张图,点数为L,边数P,并给出边的边权\(\{b_i\}\),再给处每个点的点权,求一条起点和终点相同的路径,并使其点权之和除以边权之和最大,注意,路径中点权只能被计算一次,而边权可以重复计算, (2 ≤ L ≤ 1000), (2 ≤ P ≤ 5000). 解 显然为分数规划问题,关键在点权与边权不对应上,于是自然的想法是点权移边权,而一条起点与终点相同的路径即一个联通分量,所以问题现在在于点权移边权后只对环成立,而不对联通分量成立,于是考虑证明联通分量…
POJ2182 Lost Cows 题解 描述 有\(N\)(\(2 <= N <= 8,000\))头母牛,每头母牛有自己的独一无二编号(\(1..N\)). 现在\(N\)头母牛站成一列,已知每头母牛前面编号比它小的母牛数量,求每头母牛的编号. 输入格式 第1行 : 一个整数 \(N\) 第2..N行 : 从 第2头母牛到第N头母牛 的 前面编号比它小的母牛数量 样例输入 5 1 2 1 0 样例输出 2 4 5 3 1 题解 先手造一组数据 2 1 5 4 3 // 编号序列 设比第\(…
题意描述 Sightseeing Cows G 给定一张有向图,图中每个点都有点权 \(a_i\),每条边都有边权 \(e_i\). 求图中一个环,使 "环上个点权之和" 除以 "环上各边权之和" 最大.输出最大值. 解释一下,原题目中并没有点明这是一个环,但是从: 奶牛们不会愿意把同一个建筑物参观两遍. 可以看出,不管怎么走,走环一定是最优的,因为重复走相当于无故增加分母. 算法分析 据说这是一道 0/1 分数规划的题目,但是其实可以用更加通俗易懂的方法来解释.…
一道\(0/1\)分数规划+负环 POJ原题链接 洛谷原题链接 显然是\(0/1\)分数规划问题. 二分答案,设二分值为\(mid\). 然后对二分进行判断,我们建立新图,没有点权,设当前有向边为\(z=(x,y)\),\(time\)为原边权,\(fun\)为原点权,则将该边权换成\(mid\times time[z]+fun[x]\),然后在上面跑\(SPFA\). 如果有一个环使得\(\sum\{mid\times time[z]+fun[x]\}<0\),则说明\(mid\)小了,而式子…
http://www.cnblogs.com/wally/p/3228171.html 题解请戳上面 然后对于01规划的总结 1:对于一个表,求最优比例 这种就是每个点位有benefit和cost,这样就是裸的01规划 2:对于一个树,求最优比例 这种就是每条边有benefit和cost,然后通过最小生成树来判断 3:对于一个环求最优比例 这种也是每条边有benefit和cost,然后通过spfa来判断 其实01规划最核心的地方,在于构建01规划函数,构建好函数,然后根据单调性,判断大于0或者小…
题目大意:给定一个 N 个点,M 条边的有向图,点有点权,边有边权,求该有向图中的一个环,使得环上点权和与环上边权和之比最大. 题解:0/1 分数规划思想,每次二分一个 mid,在新图上跑 spfa,将问题转化成是否存在负环即可. 代码如下 #include <bits/stdc++.h> using namespace std; const int maxn=1010; const double eps=1e-4; struct node{int to;double w;}; vector&…
[BZOJ 1652][USACO 06FEB]Treats for the Cows Description FJ has purchased N (1 <= N <= 2000) yummy treats for the cows who get money for giving vast amounts of milk. FJ sells one treat per day and wants to maximize the money he receives over a given…
Popular Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 29642   Accepted: 11996 Description Every cow's dream is to become the most popular cow in the herd. In a herd of N (1 <= N <= 10,000) cows, you are given up to M (1 <= M &…
嘟嘟嘟 这题好像属于01分数规划问题,叫什么最优比率生成环. 题目概括一下,就是求一个环,满足∑v[i] / ∑c[i]最大. 我们可以堆上面的式子变个型:令 x = ∑v[i] / ∑c[i],则x * ∑c[i] = v[i] => ∑x * c[i] - v[i] = 0.于是对于任何能取到的x',满足∑x * c[i] - v[i] <= 0:对于不能取到的x', ∑x * c[i] - v[i] > 0. 于可以实数二分答案,用spfa判断负环. 然后实数二分又RE了……调了好…
题目: 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;…
题目描述 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) major landma…
题目描述 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) major landma…
题目描述 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) major landma…
SP740 TRT - Treats for the Cows 题目描述 FJ has purchased N (1 <= N <= 2000) yummy treats for the cows who get money for giving vast amounts of milk. FJ sells one treat per day and wants to maximize the money he receives over a given period time. The tr…