博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Bzoj3597: [Scoi2014]方伯伯运椰子
阅读量:6977 次
发布时间:2019-06-27

本文共 1682 字,大约阅读时间需要 5 分钟。

题面

Sol

消圈定理:如果一个费用流网络的残量网络有负环,那么这个费用流不优

于是这个题就可以建出残量网络,然后分数规划跑负环了

# include 
# define IL inline# define RG register# define Fill(a, b) memset(a, b, sizeof(a))using namespace std;typedef long long ll;IL int Input(){ RG int x = 0, z = 1; RG char c = getchar(); for(; c < '0' || c > '9'; c = getchar()) z = c == '-' ? -1 : 1; for(; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48); return x * z;}const int maxn(6005);const double eps(1e-5);int n, m, first[maxn], cnt, vis[maxn];double dis[maxn], l = 0, r = 5e4;struct Edge{ int to, next; double w;} edge[maxn];IL void Add(RG int u, RG int v, RG double w){ edge[cnt] = (Edge){v, first[u], w}, first[u] = cnt++;}IL int Dfs(RG int u, RG double w){ vis[u] = 1; for(RG int e = first[u]; e != -1; e = edge[e].next){ RG int v = edge[e].to; RG double d = dis[u] + edge[e].w + w; if(dis[v] > d){ dis[v] = d; if(vis[v] || Dfs(v, w)) return 1; } } vis[u] = 0; return 0;}IL int Check(RG double v){ for(RG int i = 1; i <= n + 2; ++i) dis[i] = 0, vis[i] = 0; for(RG int i = 1; i <= n + 2; ++i) if(Dfs(i, v)) return 1; return 0;}int main(){ n = Input(), m = Input(); for(RG int i = 1; i <= n + 2; ++i) first[i] = -1; for(RG int i = 1; i <= m; ++i){ RG int u = Input(), v = Input(), a = Input(), b = Input(), c = Input(), d = Input(); Add(u, v, b + d); if(c) Add(v, u, a - d); } while(r - l >= eps){ RG double mid = (l + r) / 2.0; if(Check(mid)) l = mid; else r = mid; } printf("%.2lf\n", r); return 0;}

转载于:https://www.cnblogs.com/cjoieryl/p/9113864.html

你可能感兴趣的文章
ASP.NET Core 实现跨站登录重定向的新姿势
查看>>
JS Date 时间格式化
查看>>
socket No route to host - sovle
查看>>
仿唐集二
查看>>
abstract的method是否可同时是static,是否可同时是native,是否可同时是synchronized?
查看>>
SQL Kerberos的原理及实验
查看>>
Cyclic Nacklace
查看>>
分布式缓存技术之Redis_01数据结构分析
查看>>
Android 学习 笔记_08. 广播机制
查看>>
RDLC换行
查看>>
ubuntu安装nginx及其默认目录结构
查看>>
printf重定向
查看>>
《c程序设计语言》读书笔记-5.9-指针转换天数和日期
查看>>
Docker
查看>>
[知识点]平衡树之Splay
查看>>
分享:Ftp上传下载工具FlashFXP
查看>>
Linux基本命令
查看>>
史上最全python面试题详解(一)(附带详细答案(持续更新))
查看>>
day17
查看>>
泛型类、泛型方法、类型通配符的使用
查看>>