[SCOI2014]方伯伯运椰子
01分数规划思维题。
题中要求交通总量不减少,那么如果总量增加的话,总费用就会增加,所以一定不是更优的解。那么总量守恒。
这是不是就想到了网络流?对于每一个节点流入量等于流出量。然后就是很有思维的一个转化了:把压缩看成退流,把扩容看成增广。
边(x, y)一次压缩,就建一条y -> x,容量为a - d的边。
边(x, y)一次增广,就建一条x -> y,容量为b + d的边。也就是一次调整多出来的费用。那么这样建完图后,图中的一个环就代表一种调整方案!
回头看题,让求某一个比值最小,那一定会想到01分数规划,令ans = max((X - Y) / k),那么ans >= (X - Y) / k,于是有ans * k + Y - X >= 0。按上述的建图,Y - X就是环上的边权和,k就是环中的点数(边数),所以这个式子相当于每经过一条边,这条边的边权就加一个ans,那么ans * k + Y - X >= 0就可以写成Σ(ans + ei) >= 0。二分的时候,如果存在负环,说明mid取小了,向右二分;否则向左二分。
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<vector>
#include<stack>
#include<queue>
using namespace std;
#define enter puts("")
#define space putchar(' ')
#define Mem(a, x) memset(a, x, sizeof(a))
#define rg register
typedef long long ll;
typedef double db;
const int INF = 0x3f3f3f3f;
const db eps = 1e-;
const int maxn = 5e3 + ;
const int maxe = 3e3 + ;
inline ll read()
{
ll ans = ;
char ch = getchar(), last = ' ';
while(!isdigit(ch)) {last = ch; ch = getchar();}
while(isdigit(ch)) {ans = ans * + ch - ''; ch = getchar();}
if(last == '-') ans = -ans;
return ans;
}
inline void write(ll x)
{
if(x < ) x = -x, putchar('-');
if(x >= ) write(x / );
putchar(x % + '');
} int n, m;
struct Edge
{
int nxt, to, w;
}e[maxe << ];
int head[maxn], ecnt = -;
void addEdge(int x, int y, int w)
{
e[++ecnt] = (Edge){head[x], y, w};
head[x] = ecnt;
} db dis[maxn];
bool vis[maxn], mak[maxn];
bool spfa(int now, db x)
{
vis[now] = mak[now] = ;
for(int i = head[now]; i != -; i = e[i].nxt)
{
if(dis[e[i].to] > dis[now] + e[i].w + x)
{
dis[e[i].to] = dis[now] + e[i].w + x;
if(vis[e[i].to]) return ;
if(spfa(e[i].to, x)) return ;
}
}
vis[now] = ;
return ;
} bool judge(db x)
{
Mem(vis, ); Mem(mak, );
for(int i = ; i <= n + ; ++i)
if(!mak[i])
{
if(spfa(i, x)) return ;
}
return ;
} int main()
{
Mem(head, -);
n = read(); m = read();
for(int i = ; i <= m; ++i)
{
int x = read(), y = read(), a = read(), b = read(), c = read(), d = read();
if(c) addEdge(y, x, a - d);
addEdge(x, y, b + d);
}
db L = , R = 1e5;
while(R - L > eps)
{
db mid = (L + R) / 2.00;
if(judge(mid)) L = mid;
else R = mid;
}
printf("%.2lf\n", L);
return ;
}
[SCOI2014]方伯伯运椰子的更多相关文章
- bzoj 3597: [Scoi2014]方伯伯运椰子 0/1分数规划
3597: [Scoi2014]方伯伯运椰子 Time Limit: 30 Sec Memory Limit: 64 MBSubmit: 144 Solved: 78[Submit][Status ...
- bzoj 3597: [Scoi2014]方伯伯运椰子 [01分数规划 消圈定理 spfa负环]
3597: [Scoi2014]方伯伯运椰子 题意: from mhy12345 给你一个满流网络,对于每一条边,压缩容量1 需要费用ai,扩展容量1 需要bi, 当前容量上限ci,每单位通过该边花费 ...
- bzoj3597[Scoi2014]方伯伯运椰子 01分数规划+spfa判负环
3597: [Scoi2014]方伯伯运椰子 Time Limit: 30 Sec Memory Limit: 64 MBSubmit: 594 Solved: 360[Submit][Statu ...
- 3597: [Scoi2014]方伯伯运椰子[分数规划]
3597: [Scoi2014]方伯伯运椰子 Time Limit: 30 Sec Memory Limit: 64 MB Submit: 404 Solved: 249 [Submit][Sta ...
- bzoj 3597: [Scoi2014]方伯伯运椰子
Description Input 第一行包含二个整数N,M 接下来M行代表M条边,表示这个交通网络 每行六个整数,表示Ui,Vi,Ai,Bi,Ci,Di 接下来一行包含一条边,表示连接起点的边 Ou ...
- bzoj 3597 [Scoi2014] 方伯伯运椰子 - 费用流 - 二分答案
题目传送门 传送门 题目大意 给定一个费用流,每条边有一个初始流量$c_i$和单位流量费用$d_i$,增加一条边的1单位的流量需要花费$b_i$的代价而减少一条边的1单位的流量需要花费$a_i$的代价 ...
- 2019.03.28 bzoj3597: [Scoi2014]方伯伯运椰子(01分数规划)
传送门 题意咕咕咕有点麻烦不想写 思路: 考虑加了多少一定要压缩多少,这样可以改造边. 于是可以通过分数规划+spfaspfaspfa解决. 代码: #include<bits/stdc++.h ...
- BZOJ3597 SCOI2014方伯伯运椰子(分数规划+spfa)
即在总流量不变的情况下调整每条边的流量.显然先二分答案变为求最小费用.容易想到直接流量清空跑费用流,但复杂度略有些高. 首先需要知道(不知道也行?)一种平时基本不用的求最小费用流的算法——消圈法.算法 ...
- Bzoj3597: [Scoi2014]方伯伯运椰子
题面 传送门 Sol 消圈定理:如果一个费用流网络的残量网络有负环,那么这个费用流不优 于是这个题就可以建出残量网络,然后分数规划跑负环了 # include <bits/stdc++.h> ...
随机推荐
- linux 登陆失败处理
1.备份要操作的两个配置文件 cp /etc/pam.d/sshd /etc/pam.d/sshd.bak cp /etc/pam.d/login /etc/pam.d/login.bak 2.检查是 ...
- ZABBIX 监控基本报警故障
CPU触发器: 1)Processor load is too high on {HOST.NAME} {HOST.NAME}上处理器负载太高 触发器表达式:{Zabbix server:system ...
- 使用PagerSlidingTabStrip实现顶部导航栏
使用PagerSlidingTabStrip配合ViewPager实现顶部导航栏. 效果图如下: PagerSlidingTabStrip是github上的一个开源项目,项目地址如下 ...
- Kettle集群部署(1台Windows主机和2台Linux服务器)
不多说,直接上干货! http://blog.csdn.net/jianglushou9763/article/details/70859616
- TOJ 1885 Triangles
Description It is always very nice to have little brothers or sisters. You can tease them, lock them ...
- jQuery前端数据通用验证库,解放你的双手
这个简易的验证库,应该能完成90%的基本验证,包括失去焦点时的验证,以及点击提交按钮时的验证.后端的那我就无能为办了,只能是谁用就谁自个儿去写了:). 先上一段调用的代码吧,JS代码说少也不少了,就不 ...
- [转]Using NLog for ASP.NET Core to write custom information to the database
本文转自:https://github.com/NLog/NLog/issues/1366 In the previous versions of NLog it was easily possibl ...
- 浅谈前端与SEO
转载地址: https://blog.csdn.net/lzm18064126848/article/details/53385274?tdsourcetag=s_pctim_aiomsg SEO(S ...
- 解决The current branch is not configured for pull No value for key branch.master.merge found in config
使用Git Pull项目的时候出现这个问题: The current branch is not configured for pull No value for key branch.master. ...
- 什么是PV,什么是UV,什么是IP. 流量统计的各种数据!
pv流量 什么是PV? 解答:PV是指页面刷新的次数,每一次页面刷新,就算做一次pv流量. PV高一定代表来访者多吗? 解答:不一定如此,一般来说,PV与来访者的数量成正比,但是PV并不直接决定页面的 ...