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…
题目大意:在一个无向图里找一个环,是的点权和除以边权和最大 思路: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…
典型的求最优比例环问题 參考资料: http://blog.csdn.net/hhaile/article/details/8883652 此题中,给出每一个点和每条边的权值,求一个环使 ans=∑点权/∑边权 最大. 由于题目要求一个环,并且必定是首尾相接的一个我们理解的纯粹的环,不可能是其它样子的环, 所以我们能够把一条边和指向的点看做总体处理. 上面方程能够化为:ans×e[i]-p[i]=0 以它为边权二分答案,spfa求负环,有负环则该ans可行,增大下界. 若一直不可行,则无解. #…
题目链接: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分数规划差点儿都是二分或者迭代比值,从而…
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…
[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…
题目链接: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…
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…
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). 解 显然为分数规划问题,关键在点权与边权不对应上,于是自然的想法是点权移边权,而一条起点与终点相同的路径即一个联通分量,所以问题现在在于点权移边权后只对环成立,而不对联通分量成立,于是考虑证明联通分量…
题意描述 Sightseeing Cows G 给定一张有向图,图中每个点都有点权 \(a_i\),每条边都有边权 \(e_i\). 求图中一个环,使 "环上个点权之和" 除以 "环上各边权之和" 最大.输出最大值. 解释一下,原题目中并没有点明这是一个环,但是从: 奶牛们不会愿意把同一个建筑物参观两遍. 可以看出,不管怎么走,走环一定是最优的,因为重复走相当于无故增加分母. 算法分析 据说这是一道 0/1 分数规划的题目,但是其实可以用更加通俗易懂的方法来解释.…
http://poj.org/problem?id=3621 全文翻译参自洛谷:https://www.luogu.org/problemnew/show/P2868 题目大意:一个有向图,每个点都有一个价值,每条路通过需要一定时间,求出一个回路使得价值和/时间和最大.(重复经过一个点不会额外增加价值) 按照01分数规划的套路,我们显然可以将路的边权更改为时间*枚举的答案-目的地价值,然后找一个环. 如果这个环是一个负环,那么显然答案还可以变得更大,反之则需要变小. 所以我们需要用spfa判断图…
一道\(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\)小了,而式子…
Sightseeing Time Limit: 2000MS   Memory Limit: 65536K Total Submissions:10005   Accepted: 3523 Description Tour operator Your Personal Holiday organises guided bus trips across the Benelux. Every day the bus moves from one city S to another city F. O…
Sightseeing Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9247   Accepted: 3242 Description Tour operator Your Personal Holiday organises guided bus trips across the Benelux. Every day the bus moves from one city S to another city F. O…
题目 Tour operator Your Personal Holiday organises guided bus trips across the Benelux. Every day the bus moves from one city S to another city F. On this way, the tourists in the bus can see the sights alongside the route travelled. Moreover, the bus…
有n个节点的m条无向边的图,节点编号为1~n 然后有点权和边权,给出q个询问,每一个询问给出2点u,v 输出u,v的最短距离 这里的最短距离规定为: u到v的路径的所有边权+u到v路径上最大的一个点权的和(点权也可以是u,v) n<=1000 m<=20000 Q<=20000 时限:5000ms 没有点权的话,好处理 加了点权呢? 我们可以先枚举n个节点,跑n次spfa,当枚举节点u时,我们默认节点u是所有路径上点权最大的一个点 即我们枚举节点u时,我们先把点权比u大的节点删除了,在剩…
题目描述 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…
传送门 用dijkstra比较好,spfa可能有的重复 dis[x][2]:dis[x][0]表示起点到x的最短路.dis[x][1]表示起点到x的次短路: tot[x][2]:tot[x][0]表示起点到x的最短路条数.tot[x][1]表示起点到x的次短路的条数: vis[x][2]对应于x和0.1功能为记录该点是否被访问! 那么如何更新最小和次小路呢?显然我们容易想到下面的方法: 1.if(x<最小)更新最小,次小:2.else if(x==最小)更新方法数:3.else if(x<次小…
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)大…
http://www.cnblogs.com/wally/p/3228171.html 题解请戳上面 然后对于01规划的总结 1:对于一个表,求最优比例 这种就是每个点位有benefit和cost,这样就是裸的01规划 2:对于一个树,求最优比例 这种就是每条边有benefit和cost,然后通过最小生成树来判断 3:对于一个环求最优比例 这种也是每条边有benefit和cost,然后通过spfa来判断 其实01规划最核心的地方,在于构建01规划函数,构建好函数,然后根据单调性,判断大于0或者小…
感觉去年9月的自己好$naive$ http://www.cnblogs.com/candy99/p/5868948.html 现在不也是嘛 裸题,具体看学习笔记 二分答案之后判负环就行了 $dfs$版超快 #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <queue> using namespace std; typed…
题意 题目链接 Sol 复习一下01分数规划 设\(a_i\)为点权,\(b_i\)为边权,我们要最大化\(\sum \frac{a_i}{b_i}\).可以二分一个答案\(k\),我们需要检查\(\sum \frac{a_i}{b_i} \geqslant k\)是否合法,移向之后变为\(\sum_{a_i} - k\sum_{b_i} \geqslant 0\).把\(k * b_i\)加在出发点的点权上检查一下有没有负环就行了 #include<bits/stdc++.h> #defin…