poj 2049(二分+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…
poj 2049(二分+spfa判负环) 给你一堆字符串,若字符串x的后两个字符和y的前两个字符相连,那么x可向y连边.问字符串环的平均最小值是多少.1 ≤ n ≤ 100000,有多组数据. 首先根据套路,二分是显然的.然后跑一下spfa判断正环就行了. 然而我被no solution坑了十次提交.. #include <cctype> #include <cstdio> #include <cstring> using namespace std; const in…
题目链接:http://poj.org/problem?id=3259 题目大意是给你n个点,m条双向边,w条负权单向边.问你是否有负环(虫洞). 这个就是spfa判负环的模版题,中间的cnt数组就是记录这个点松弛进队的次数,次数超过点的个数的话,就说明存在负环使其不断松弛. #include <iostream> #include <cstdio> #include <cstring> #include <queue> using namespace st…
题意描述: 见原LOJ:https://loj.ac/problem/10084 题解: 假设所求的平均最小值为X,环上各个边的权值分别为A1,A2...Ak,可以得到: X=(A1+A2+A3+...+Ak)/K, A1+A2+A3+...+Ak=X*K, 移项可得:(A1-X)+(A2-X)+(A3-X)+...+(Ak-X)=0, 另外注意到式子中的等于号可以改为大于等于,那么我们可以二分结果ans,然后判断是否存在一组解满足(A1+A2+A3+...+Ak)/k<=ans, 即判断:(A…
Description While exploring his many farms, Farmer John has discovered a number of amazing wormholes. A wormhole is very peculiar because it is a one-way path that delivers you to its destination at a time that is BEFORE you entered the wormhole! Eac…
题目链接: [APIO2017]商旅 枚举任意两个点$(s,t)$,求出在$s$买入一个物品并在$t$卖出的最大收益. 新建一条从$s$到$t$的边,边权为最大收益,长度为原图从$s$到$t$的最短路,最短路用$floyd$求即可. 对于原图的边,边权为$0$,长度为输入长度. 对于新图,需要找到一个环使得换上边的边权和比长度和最大. 显然二分答案然后分数规划,之后就变成了判断图中是否有负环,用SPFA判负环即可. 注意此题卡精,需要使用$long\ double$. #include<set>…
Wormholes Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 42366 Accepted: 15560 传送门 Description While exploring his many farms, Farmer John has discovered a number of amazing wormholes. A wormhole is very peculiar because it is a one-way p…
King Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 14791   Accepted: 5226 Description Once, in one kingdom, there was a queen and that queen was expecting a baby. The queen prayed: ``If my child was a son and if only he was a sound kin…
传送门 答案只保留了6位小数WA了两次233. 这就是一个简单的01分数规划. 直接二分答案,根据图中有没有负环存在进行调整. 注意二分边界. 另外dfs版spfa判负环真心快很多. 代码: #include<bits/stdc++.h> #define N 3005 #define M 10005 using namespace std; inline int read(){ int ans=0; char ch=getchar(); while(!isdigit(ch))ch=getcha…
BZOJ 4898 [APIO2017] 商旅 | SPFA判负环 分数规划 更清真的题面链接:https://files.cnblogs.com/files/winmt/merchant%28zh_CN%29.pdf 题解 --APIO2017那天我似乎在--北京一日游-- [更新]诶?我--我Rank1了?//虽然只有不几个人做这道题 正经的题解: 二分答案,如果存在一种环路使得[总获利/总路程 > mid],那么这个环路的[总(获利 - 路程 * mid)]一定大于0,换句话说,把边权换成…