3597: [Scoi2014]方伯伯运椰子

Time Limit: 30 Sec  Memory Limit: 64 MB
Submit: 144  Solved: 78
[Submit][Status][Discuss]

Description

.................

Input

第一行包含二个整数N,M

接下来M行代表M条边,表示这个交通网络
每行六个整数,表示Ui,Vi,Ai,Bi,Ci,Di
接下来一行包含一条边,表示连接起点的边

Output

一个浮点数,保留二位小数。表示答案,数据保证答案大于0

Sample Input

5 10
1 5 13 13 0 412
2 5 30 18 396 148
1 5 33 31 0 39
4 5 22 4 0 786
4 5 13 32 0 561
4 5 3 48 0 460
2 5 32 47 604 258
5 7 44 37 75 164
5 7 34 50 925 441
6 2 26 38 1000 22

Sample Output

103.00

HINT

1<=N<=5000

0<=M<=3000
1<=Ui,Vi<=N+2
0<=Ai,Bi<=500
0<=Ci<=10000
0<=Di<=1000
 
  根本搞不懂网上的什么消圈算法,我的思路是这样的:不用想先肯定是枚举答案若ans<delta/tot,那么delta-ans*tot>0,我们先将所有有流的边假设退掉,然后将每条边分为撤销默认操作和新的扩边操作,这样可以直接通过0/1分数规划套费用流解决了,具体怎么加加减减比较烦人,可以直接参考代码。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAXN 5100
#define MAXE MAXV*20
#define MAXV MAXN*2
#define inf 1e100
#define INF 0x3f3f3f3f
#define eps 1e-4
typedef double real;
struct Edge
{
int np;
int val;
real cost;
Edge *neg,*next;
}E[MAXE],*V[MAXV];
int tope=-;
int sour=,sink=; void addedge(int x,int y,int v,real c)
{
// cout<<"Add: "<<x<<" "<<y<<" "<<v<<" "<<c<<endl;
E[++tope].np=y;
E[tope].val=v;
E[tope].cost=c;
E[tope].next=V[x];
V[x]=&E[tope]; E[++tope].np=x;
E[tope].val=;
E[tope].cost=-c;
E[tope].next=V[y];
V[y]=&E[tope]; V[x]->neg=V[y];
V[y]->neg=V[x];
}
int q[MAXV*];
int vis[MAXV],vistime;
real dis[MAXV];
Edge *prve[MAXV];
int prv[MAXV];
int n,m;
bool spfa()
{
int now=sour;
Edge *ne;
for (int i=;i<MAXV;i++)
dis[i]=-inf;
dis[now]=;
vis[now]=++vistime;
q[]=now;
int head=-,tail=;
while (head<tail)
{
now=q[++head];
vis[now]=;
for (ne=V[now];ne;ne=ne->next)
{
if (ne->val && dis[ne->np]<dis[now]+ne->cost)
{
dis[ne->np]=dis[now]+ne->cost;
prv[ne->np]=now;
prve[ne->np]=ne;
if (vis[ne->np]!=vistime)
{
vis[ne->np]=vistime;
q[++tail]=ne->np;
}
}
}
}
return dis[sink]!=-1e100;
}
pair<int,real> cost_flow()
{
int x;
int totf=;
real sumc=;
int maxf;
while (spfa())
{
maxf=INF;
for (x=sink;x!=sour;x=prv[x])
maxf=min(maxf,prve[x]->val);
for (x=sink;x!=sour;x=prv[x])
{
prve[x]->val-=maxf;
prve[x]->neg->val+=maxf;
}
sumc+=maxf*dis[sink];
totf+=maxf;
}
return make_pair(totf,sumc);
}
struct edge
{
int x,y,vdec,vinc,vcur,vcst;
}e[MAXE];
int main()
{
//freopen("input.txt","r",stdin);
int x,y,z;
scanf("%d%d",&n,&m);
sour=n+;
sink=n+;
int mxflow;
for (int i=;i<m;i++)
{
scanf("%d%d%d%d%d%d",&e[i].x,&e[i].y,&e[i].vdec,&e[i].vinc,&e[i].vcur,&e[i].vcst);
if (e[i].x==sour)
mxflow=e[i].vcur;
}
double l,r,mid;
l=,r=;
while (l+eps<r)
{
memset(V,,sizeof(V));
tope=-;
mid=(l+r)/;
double res=;
for (int i=;i<m;i++)
{
addedge(e[i].x,e[i].y,e[i].vcur,e[i].vdec-e[i].vcst+mid);
addedge(e[i].x,e[i].y,mxflow-e[i].vcur,-e[i].vinc-e[i].vcst-mid);
res+=e[i].vcur*(-e[i].vdec+e[i].vcst-mid);
}
res+=cost_flow().second;
if (res<=)
r=mid;
else
l=mid;
}
printf("%.2lf\n",l);
return ;
}

bzoj 3597: [Scoi2014]方伯伯运椰子 0/1分数规划的更多相关文章

  1. bzoj 3597: [Scoi2014]方伯伯运椰子 [01分数规划 消圈定理 spfa负环]

    3597: [Scoi2014]方伯伯运椰子 题意: from mhy12345 给你一个满流网络,对于每一条边,压缩容量1 需要费用ai,扩展容量1 需要bi, 当前容量上限ci,每单位通过该边花费 ...

  2. bzoj 3597: [Scoi2014]方伯伯运椰子

    Description Input 第一行包含二个整数N,M 接下来M行代表M条边,表示这个交通网络 每行六个整数,表示Ui,Vi,Ai,Bi,Ci,Di 接下来一行包含一条边,表示连接起点的边 Ou ...

  3. 2019.03.28 bzoj3597: [Scoi2014]方伯伯运椰子(01分数规划)

    传送门 题意咕咕咕有点麻烦不想写 思路: 考虑加了多少一定要压缩多少,这样可以改造边. 于是可以通过分数规划+spfaspfaspfa解决. 代码: #include<bits/stdc++.h ...

  4. bzoj 3597 [Scoi2014] 方伯伯运椰子 - 费用流 - 二分答案

    题目传送门 传送门 题目大意 给定一个费用流,每条边有一个初始流量$c_i$和单位流量费用$d_i$,增加一条边的1单位的流量需要花费$b_i$的代价而减少一条边的1单位的流量需要花费$a_i$的代价 ...

  5. 3597: [Scoi2014]方伯伯运椰子[分数规划]

    3597: [Scoi2014]方伯伯运椰子 Time Limit: 30 Sec  Memory Limit: 64 MB Submit: 404  Solved: 249 [Submit][Sta ...

  6. BZOJ 3597 SCOI2014 方伯伯送椰子 网络流分析+SPFA

    原题链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3597 Description 四川的方伯伯为了致富,决定引进海南的椰子树.方伯伯的椰子园十 ...

  7. bzoj3597[Scoi2014]方伯伯运椰子 01分数规划+spfa判负环

    3597: [Scoi2014]方伯伯运椰子 Time Limit: 30 Sec  Memory Limit: 64 MBSubmit: 594  Solved: 360[Submit][Statu ...

  8. Bzoj3597: [Scoi2014]方伯伯运椰子

    题面 传送门 Sol 消圈定理:如果一个费用流网络的残量网络有负环,那么这个费用流不优 于是这个题就可以建出残量网络,然后分数规划跑负环了 # include <bits/stdc++.h> ...

  9. [SCOI2014]方伯伯运椰子

    嘟嘟嘟 01分数规划思维题. 题中要求交通总量不减少,那么如果总量增加的话,总费用就会增加,所以一定不是更优的解.那么总量守恒. 这是不是就想到了网络流?对于每一个节点流入量等于流出量.然后就是很有思 ...

随机推荐

  1. linux上gcc

    查看gcc版本号 rpm -qa | grep gcc gnu的gcc是linux/unix下开发的,不能直接在window下运行.window下有gcc的移植版本.就是楼上说的MinGW和cygwi ...

  2. [转] Android进阶——安卓接入微信,获取OpenID

    PS: sendAuthRequest拿到code,通过code拿到access_token和openId,access_token可以拿到用户的信息 http://blog.csdn.net/hao ...

  3. Java基础知识强化之集合框架笔记66:Map集合面试题之HashMap和Hashtable区别(重要)

    1. HashMap和Hashtable区别 ? • Hashtable:线程安全,效率低.不允许null键和null值 • HashMap:线程不安全,效率高.允许null键和null值 packa ...

  4. java.sql.SQLException: ORA-28001: the password has expired。

    java.sql.SQLException: ORA-28001: the password has expired. Oracle11g的密码过期. 原因:是由于oracle11g中默认在defau ...

  5. 新增的html5中js获取方法

    一.querySelector   获取的选择器与jquery的选择器相同

  6. 参加魅族 flyme 互联网编程大赛的一些感受

    为期两天的 flyme 编程大赛已经结束了,自己也在这次大赛中深有感触,受益颇丰. 在这次大赛里,认识到了很多厉害的开发者,有单打独斗的,也有四五成群的.开幕致辞上看到很多非常有创意的点子,感觉每个队 ...

  7. c#面向对象编程基础

    1.  为什么要有面向对象? (1)       增加代码重用. (2)降低维护负担,将具备独特性质的代码封装起来,修改程序时,相互不会影响. 2.数据封装用来解决全局变量不易维护的问题. 3.多态: ...

  8. android studio环境搭建-笔记1

    自己干了几年测试(功能性的),最近比较闲,就自己学习下android(以前也有所接触,但那是几年前的一点皮毛,都忘记了). 先搭建谷歌推出的android studio(以前用eclipse搭建总觉得 ...

  9. Deep Learning 学习随记(三)Softmax regression

    讲义中的第四章,讲的是Softmax 回归.softmax回归是logistic回归的泛化版,先来回顾下logistic回归. logistic回归: 训练集为{(x(1),y(1)),...,(x( ...

  10. requirejs实践一 加载JavaScript文件

    首先,目录如下(根目录有一个index.html文件.有一个scripts文件夹): scripts文件夹有如下的文件 以下是index.html代码 <!DOCTYPE html> &l ...