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 配置 Apache mysql php最新版

    第一部分:安装mysql 官方下载 mysql5.6.19 64位的rpm格式文件 0.rpm 四个mysql5.6.19 卸载默认的mysql yum -y remove mysql-libs-* ...

  2. 一款很不错的FLASH时种插件

    直接贴一段代码上来,大家看看效果: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " ...

  3. java查询手机号码归属地

    package com; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamRe ...

  4. Find Security Bugs研究,邀请志同道合者一起参与

    Find Security Bugs研究,邀请志同道合者一起参与http://automationqa.com/forum.php?mod=viewthread&tid=2803&fr ...

  5. IIS 返回 405 - 不允许用于访问此页的 HTTP 谓词。终极解决办法!!!!

    首先这个问题在其他网站(CSDN,新浪博客等) 回答基本都是没有回答到"根本"上面来(而且总在纠结要不要勾选"全部谓词") 我是自己对比了本地IIS之后得出的结 ...

  6. 阿里云ECS被攻击

    今天发现阿里云ECS被攻击了,记录一下, /1.1 Match1:{ :;};/usr/bin/perl -e 'print .content-type: text/plain.r.n.r.nxsuc ...

  7. WildFly 9.0.2+mod_cluster-1.3.1 集群配置

    一.配置背景 最近使用WildFly 9.0.2作为中间件开发系统,给客户不熟的时候需要使用集群来进行负载均衡,一开始想到是使用Nginx.但是只通过Nginx使用 ip_hash 模式没有做到ses ...

  8. UIView的常见属性

    UIView的常见属性: @interface UIView : UIResponder<NSCoding, UIAppearance, UIAppearanceContainer, UIDyn ...

  9. mysql:1153 Got a packet bigger than ‘max_allowed_packet’ bytes的解决方法

    备份还原或数据导入报错1153:Got a packet bigger than'max_allowed_packet'bytes的问题 这个问题可以有2个解决方法: 1.临时修改: mysql> ...

  10. spring mvc 错误

    No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin  //跨域问题 respons ...