poj 3621 二分+spfa】的更多相关文章

http://poj.org/problem?id=3621 求一个环的{点权和}除以{边权和},使得那个环在所有环中{点权和}除以{边权和}最大. 0/1整数划分问题 令在一个环里,点权为v[i],对应的边权为e[i],  即要求:∑(i=1,n)v[i]/∑(i=1,n)e[i]最大的环(n为环的点数),  设题目答案为ans,  即对于所有的环都有 ∑(i=1,n)(v[i])/∑(i=1,n)(e[i])<=ans  变形得ans* ∑(i=1,n)(e[i])>=∑(i=1,n)(v…
题意:给出一个有向图,问求一个回路,使得回路上的点权之和/边权之和最大. 这题主要是分析出如何确定ans值.我们将(a1*x1+a2*x2+..+an*xn)/(b1*x1+b2*x2+..+bn*xn)=L,转换为:x1*(a1-b1*L)+x2*(a2-b2*L)+...xn*(an-bn*L)=0 则每次枚举L的值,spfa中边权值为len[]*L-a[],若存在负环回路(即一个点访问次数超过n次)则表示L的值小了,增大L值;反之减小L值. 代码: #include<iostream>…
题目链接: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…
poj 2049(二分+spfa判负环) 给你一堆字符串,若字符串x的后两个字符和y的前两个字符相连,那么x可向y连边.问字符串环的平均最小值是多少.1 ≤ n ≤ 100000,有多组数据. 首先根据套路,二分是显然的.然后跑一下spfa判断正环就行了. 然而我被no solution坑了十次提交.. #include <cctype> #include <cstdio> #include <cstring> using namespace std; const in…
Trucking 题目连接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2224 Descriptionww.co A certain local trucking company would like to transport some goods on a cargo truck from one place to…
依然是学习分析方法的一道题 求一个长度为n的序列中的一个平均值最大且长度不小于L的子段,输出最大平均值 最值问题可二分,从而转变为判定性问题:是否存在长度大于等于L且平均值大于等于mid的字段和 每个数与mid作差再转变为求非负子段 子段和问题应该利用前缀和C,长度大于等于L的字段和最大值可表示为 max{Aj+1 + Aj+2 ... + Ai},i-j+1-1>=L,j+1>=1 等价于 max{Ci-min{Cj}},L<=i<=n,0<=j<=i-L 注意是i=…
洛谷P1462 通往奥格瑞玛的道路 二分费用. 用血量花费建图,用单源最短路判断 \(1\) 到 \(n\) 的最短路花费是否小于 \(b\) .二分时需要不断记录合法的 \(mid\) 值. 这里建议使用while(l <= r),会避免出现答案为 \(r\) 时和答案AFK搞混,样例就是这种情况. 复杂度为 \(O(\log n) \times\) 最短路的复杂度. 二分 + Dijkstra版本,复杂度为 \(O(\log n \times E\log E)\) . #include<s…
Telephone Lines Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8856   Accepted: 3211 Description Farmer John wants to set up a telephone line at his farm. Unfortunately, the phone company is uncooperative, so he needs to pay for some of…
Farmer John wants to set up a telephone line at his farm. Unfortunately, the phone company is uncooperative, so he needs to pay for some of the cables required to connect his farm to the phone system. There are N (1 ≤ N ≤ 1,000) forlorn telephone pol…