01分数规划复习. 这东西有一个名字叫做最优比率环. 首先这个答案具有单调性,我们考虑如何检验. 设$\frac{\sum_{i = 1}^{n}F_i}{\sum_{i = 1}^{n}T_i} = e$,我们需要检验的就是$\sum_{i = 1}^{n}(F_i - mid * T_i) \geq 0$是否存在. 感觉这玩意不好算,再变形一下:$\sum_{i = 1}^{n}(e * T_i - F_i) < 0$,就变成一个负环的检验了. $F_i$应当可以任取一条有向边的入点和出点.…
一道\(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\)小了,而式子…
题目戳这里 一句话题意 L个点,P条有向边,求图中最大比率环(权值(Fun)与长度(Tim)的比率最大的环). Solution 巨说这是0/1分数规划. 话说 0/1分数规划 是真的难,但貌似有一些规律,总是离不开一个二分和带mid的不等式. 记环S=({vi},{ei}), 其中{vi}为环上结点的集合,{ei}为环上的边的集合 我们先分析一波公式:不过是要求\(\sum_{i=1}^{t}Fun[v[i]]/\sum_{i=1}^{t}Tim[e[i]]>mid\) 最小 不难想到要二分一…
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…
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…
题目描述 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…
题意 题目链接 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…
题面 这道题是一道标准的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…