BZOJ 3130 [Sdoi2013]费用流 ——网络流
【题目分析】
很容易想到,可以把P放在流量最大的边上的时候最优。
所以二分网络流,判断什么时候可以达到最大流。
流量不一定是整数,所以需要实数二分,整数是会WA的。
【代码】
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib> //#include <map>
#include <set>
#include <queue>
#include <string>
#include <iostream>
#include <algorithm> using namespace std; #define maxn 1005
#define me 50005
#define inf 0x3f3f3f3f
#define F(i,j,k) for (int i=j;i<=k;++i)
#define D(i,j,k) for (int i=j;i>=k;--i)
#define eps 1e-8 void Finout()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
#endif
} int Getint()
{
int x=0,f=1; char ch=getchar();
while (ch<'0'||ch>'9') {if (ch=='-') f=-1; ch=getchar();}
while (ch>='0'&&ch<='9') {x=x*10+ch-'0'; ch=getchar();}
return x*f;
}
int h[me],to[me<<1],ne[me<<1];
double fl[me<<1];
int en=0,S=0,T=me-1;
int lim[me]; void add(int a,int b,double c)
{
// cout<<a<<" "<<b<<" "<<c<<endl;
to[en]=b; ne[en]=h[a]; fl[en]=c; h[a]=en++;
to[en]=a; ne[en]=h[b]; fl[en]=0; h[b]=en++;
} int map[maxn],tag=0; bool tell()
{
queue <int> q;
memset(map,-1,sizeof map);
map[S]=0;
q.push(S);
while (!q.empty())
{
int x=q.front(); q.pop();
for (int i=h[x];i>=0;i=ne[i])
{
if (map[to[i]]==-1&&fl[i]>eps)
{
map[to[i]]=map[x]+1;
q.push(to[i]);
}
}
}
if (map[T]!=-1) return true;
return false;
} double zeng(int k,double r)
{
if (k==T) return r;
double ret=0;
for (int i=h[k];i>=0&&ret<r;i=ne[i])
if (map[to[i]]==map[k]+1&&fl[i]>eps)
{
double tmp=zeng(to[i],min(fl[i],(double)r-ret));
ret+=tmp; fl[i]-=tmp; fl[i^1]+=tmp;
}
if (!ret) map[k]=-1;
return ret;
} int n,a[maxn],b[maxn],c[maxn],m,p; int main()
{
Finout();
memset(h,-1,sizeof h);
n=Getint(); m=Getint(); p=Getint();
S=1;T=n;
int maxx=0;
F(i,1,m)
{
a[i]=Getint();
b[i]=Getint();
c[i]=Getint();
add(a[i],b[i],(double)c[i]);
maxx=max(c[i],maxx);
}
double ans=0,tmp;
while (tell()) while(tmp=zeng(S,(double)inf)) ans+=tmp;
cout<<ans+eps<<endl;
double l=0,r=(double)maxx;
while (l+eps<r)
{
// cout<<l<<" "<<r<<endl;
double mid=(l+r)/2;
en=0;memset(h,-1,sizeof h);
F(i,1,m) add(a[i],b[i],min(mid,(double)c[i]));
double now=0,tmp;
while (tell()) while (tmp=zeng(S,(double)inf)) now+=tmp;
if (fabs(now-ans)<=eps) r=mid;
else l=mid;
}
printf("%.5f\n",l*p);
}
BZOJ 3130 [Sdoi2013]费用流 ——网络流的更多相关文章
- BZOJ 3130: [Sdoi2013]费用流 网络流+二分
3130: [Sdoi2013]费用流 Time Limit: 10 Sec Memory Limit: 128 MBSec Special JudgeSubmit: 1230 Solved: ...
- BZOJ 3130: [Sdoi2013]费用流 网络流 二分 最大流
https://www.lydsy.com/JudgeOnline/problem.php?id=3130 本来找费用流的题,权当复习一下网络流好了. 有点麻烦的是double,干脆判断大小或者二分增 ...
- bzoj 3130 [Sdoi2013]费用流(二分,最大流)
Description Alice和Bob在图论课程上学习了最大流和最小费用最大流的相关知识. 最大流问题:给定一张有向图表示运输网络,一个源点S和一个汇点T,每条边都有最大流量.一个合法的网络 ...
- bzoj 3130: [Sdoi2013]费用流
#include<cstdio> #include<iostream> #define M 10000 #define inf 0x7fffffff #include<c ...
- 3130: [Sdoi2013]费用流
Description Alice和Bob在图论课程上学习了最大流和最小费用最大流的相关知识. 最大流问题:给定一张有向图表示运输网络,一个源点S和一个汇点T,每条边都有最大流量.一个合法的网络流方案 ...
- BZOJ 1283 序列 费用流 网络流 线性规划
https://darkbzoj.cf/problem/1283 给出一个长度为N的正整数序列Ci,求一个子序列,使得原序列中任意长度为M的子串中被选出的元素不超过K(K,M<=100) 个,并 ...
- bzoj千题计划133:bzoj3130: [Sdoi2013]费用流
http://www.lydsy.com/JudgeOnline/problem.php?id=3130 第一问就是个最大流 第二问: Bob希望总费用尽量大,那肯定是把所有的花费加到流量最大的那一条 ...
- BZOJ3130: [Sdoi2013]费用流[最大流 实数二分]
3130: [Sdoi2013]费用流 Time Limit: 10 Sec Memory Limit: 128 MBSec Special JudgeSubmit: 960 Solved: 5 ...
- P3305 [SDOI2013]费用流
题目描述 Alice和Bob在图论课程上学习了最大流和最小费用最大流的相关知识. 最大流问题:给定一张有向图表示运输网络,一个源点S和一个汇点T,每条边都有最大流量. 一个合法的网络流方案必须满足: ...
随机推荐
- uvm_env——UVM大环境(UVM Environment )
1 What is uvm_env? uvm_env is used to create and connect the uvm_components like driver, monitors , ...
- 在Ubuntu16.04安装YouCompleteMe
作为从事了4年多嵌入式Linux工作的软件工程师,最近决定完全在ubuntu上工作,使用vim进行代码的阅读和编辑,然后尝试去安装vim相关的各种插件.从来没用过代码补全的我,在网上找到了插件omni ...
- 机器学习之 PCA (二)
参考 http://www.cnblogs.com/frombeijingwithlove/p/5931872.html
- DirectX9(翻译):介绍
一.简介 二.DirectX Software Development Kit 这本帮助文档总共分为五大部分:DirectX Software Development Kit DirectX Grap ...
- PAT (Basic Level) Practise (中文)- 1024. 科学计数法 (20)
PAT (Basic Level) Practise (中文)- 1024. 科学计数法 (20) http://www.patest.cn/contests/pat-b-practise/1024 ...
- POI读word doc 03 文件的两种方法
Apache poi的hwpf模块是专门用来对word doc文件进行读写操作的.在hwpf里面我们使用HWPFDocument来表示一个word doc文档.在HWPFDocument里面有这么几个 ...
- Comet OJ 热身赛-principal
这题的话,我们分析一下,入栈的操作是: 栈空 栈顶元素和当前操作元素不属于同一类括号 栈顶元素和当前操作元素属于同一类括号,但是并不是左括号在前,右括号在后 上面三个条件有任意一个满足都应该入栈,如果 ...
- History Api以及hash操作
https://segmentfault.com/a/1190000002447556#articleHeader12 https://developer.mozilla.org/zh-CN/docs ...
- 【java】【转发】classpath、path、JAVA_HOME的作用及JAVA环境变量配置
CLASSPATH是什么?它的作用是什么? 它是javac编译器的一个环境变量.它的作用与import.package关键字有关.当你写下improt java.util.*时,编译器面对import ...
- The US in understimating Huawei, says founder Ren zhengfei
Huawei Founder Ren Zhengfei has downplayed the impact of the US executive order that cripple Huawei' ...