bzoj 3597: [Scoi2014]方伯伯运椰子 0/1分数规划
3597: [Scoi2014]方伯伯运椰子
Time Limit: 30 Sec Memory Limit: 64 MB
Submit: 144 Solved: 78
[Submit][Status][Discuss]
Description
.................
Input
第一行包含二个整数N,M
Output
一个浮点数,保留二位小数。表示答案,数据保证答案大于0
Sample Input
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
HINT
1<=N<=5000
#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分数规划的更多相关文章
- bzoj 3597: [Scoi2014]方伯伯运椰子 [01分数规划 消圈定理 spfa负环]
3597: [Scoi2014]方伯伯运椰子 题意: from mhy12345 给你一个满流网络,对于每一条边,压缩容量1 需要费用ai,扩展容量1 需要bi, 当前容量上限ci,每单位通过该边花费 ...
- bzoj 3597: [Scoi2014]方伯伯运椰子
Description Input 第一行包含二个整数N,M 接下来M行代表M条边,表示这个交通网络 每行六个整数,表示Ui,Vi,Ai,Bi,Ci,Di 接下来一行包含一条边,表示连接起点的边 Ou ...
- 2019.03.28 bzoj3597: [Scoi2014]方伯伯运椰子(01分数规划)
传送门 题意咕咕咕有点麻烦不想写 思路: 考虑加了多少一定要压缩多少,这样可以改造边. 于是可以通过分数规划+spfaspfaspfa解决. 代码: #include<bits/stdc++.h ...
- bzoj 3597 [Scoi2014] 方伯伯运椰子 - 费用流 - 二分答案
题目传送门 传送门 题目大意 给定一个费用流,每条边有一个初始流量$c_i$和单位流量费用$d_i$,增加一条边的1单位的流量需要花费$b_i$的代价而减少一条边的1单位的流量需要花费$a_i$的代价 ...
- 3597: [Scoi2014]方伯伯运椰子[分数规划]
3597: [Scoi2014]方伯伯运椰子 Time Limit: 30 Sec Memory Limit: 64 MB Submit: 404 Solved: 249 [Submit][Sta ...
- BZOJ 3597 SCOI2014 方伯伯送椰子 网络流分析+SPFA
原题链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3597 Description 四川的方伯伯为了致富,决定引进海南的椰子树.方伯伯的椰子园十 ...
- bzoj3597[Scoi2014]方伯伯运椰子 01分数规划+spfa判负环
3597: [Scoi2014]方伯伯运椰子 Time Limit: 30 Sec Memory Limit: 64 MBSubmit: 594 Solved: 360[Submit][Statu ...
- Bzoj3597: [Scoi2014]方伯伯运椰子
题面 传送门 Sol 消圈定理:如果一个费用流网络的残量网络有负环,那么这个费用流不优 于是这个题就可以建出残量网络,然后分数规划跑负环了 # include <bits/stdc++.h> ...
- [SCOI2014]方伯伯运椰子
嘟嘟嘟 01分数规划思维题. 题中要求交通总量不减少,那么如果总量增加的话,总费用就会增加,所以一定不是更优的解.那么总量守恒. 这是不是就想到了网络流?对于每一个节点流入量等于流出量.然后就是很有思 ...
随机推荐
- (转)MyEclipse2014配置Tomcat开发JavaWeb程序JSP以及Servlet
1.安装准备 1).下载安装MyEclipse2014,这已经是最新版本. 2).下载Tomcat 官网:http://tomcat.apache.org/ 我们选择8.0: http://tomca ...
- git研究1
error:src refspec master does not match any 将本地GIT版本库PUSH到一个GITHUB上一个空的版本库时出现错误,本地版本库为空, 空目录不能提交 (只 ...
- tomcat启动
http://jingyan.baidu.com/article/c33e3f48a42352ea15cbb5d4.html
- 记录下sublime text快捷方式
不得不说sublime text用过之后,爱不释手,这里收集一下常用的快捷方式: ctrl+shift+p:调出命令面板,在输入ss可以改变当前的代码的渲染和提示效果, 用起sublime text ...
- iOS 查找字符串 相同 子字符串的位置 range
问题:解决替换同一个字符串的多个相同的字符eg. xxx这个超级大土豪白送xxx一个!赶快来抢把! 将第一个xxx换成名字 将第二个xxx换成物品 两种办法 第二种办法更灵活一点 //第一种办法 ...
- sharepoint2013 新建母板页 新建页面布局 关联母板页和页面布局
1 母板页的应用和layout(页面布局)的创建和应用 母板页上传:将准备好的html和样式 通过spd中的导入方式导入模版html, 导入后: 然后在网站设置中进行转换为母板页. 随后编辑 ...
- JAVA中实现百分比
import java.text.NumberFormat; public class TeachYou { public static void main(String[] args) { //这里 ...
- Java 的自动装箱拆箱
Java 是面向对象的语言,其基本数据类型也就有了相对应的类,称为包装类.以下是基本数据类型对应的包装类: 基本数据类型 包装类 byte(1字节) Byte short(2字节) Short int ...
- Ubuntu系统的安装
在上一篇博客中,我们已经建立了一个“空白”的虚拟Ubuntu镜像,在这篇博客中,我们将介绍如何安装并进入完整的Ubuntu系统. 写在前面:不同版本的系统在安装过程中,有些操作可能会不同,但是其核心步 ...
- itoa : Convert integer to string
Quote from: http://www.cplusplus.com/reference/cstdlib/itoa/ function Required header : <s ...