zoukankan      html  css  js  c++  java
  • BZOJ 3130 二分+网络流

    思路:
    不被题目忽悠就是思路
    二分一下max 判一下等不等于最大流
    搞定

    7 9 1
    1 2 3
    1 3 3
    2 3 3
    3 4 2
    3 5 2
    3 6 1
    4 7 2
    5 7 2
    6 7 2

    这里有组Bob是小数的例子

    //By SiriusRen
    #include <queue>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    using namespace std;
    #define N 105
    #define M 2222
    #define eps 1e-7
    int n,m,p,xx[M],yy[M];
    int first[N],vis[N],next[M],v[M],tot;
    double w[M],l,r,Ans,zz[M];
    void Add(int x,int y,double z){w[tot]=z,v[tot]=y,next[tot]=first[x],first[x]=tot++;}
    void add(int x,int y,double z){Add(x,y,z),Add(y,x,0);}
    void init(){memset(first,-1,sizeof(first)),tot=0;}
    bool tell(){
        memset(vis,-1,sizeof(vis)),vis[1]=0;
        queue<int>q;q.push(1);
        while(!q.empty()){
            int t=q.front();q.pop();
            for(int i=first[t];~i;i=next[i])
                if(w[i]>eps&&vis[v[i]]==-1)
                    vis[v[i]]=vis[t]+1,q.push(v[i]);
        }return ~vis[n];
    }
    double zeng(int x,double y){
        if(x==n)return y;
        double r=0;
        for(int i=first[x];~i&&y>r;i=next[i])
            if(w[i]>eps&&vis[v[i]]==vis[x]+1){
                double t=zeng(v[i],min(y-r,w[i]));
                w[i]-=t,w[i^1]+=t,r+=t;
            }
        if(r<eps)vis[x]=-1;
        return r;
    }
    double flow(){
        double tmp,ans=0;
        while(tell())while((tmp=zeng(1,1000000.0))>eps)ans+=tmp;
        return ans;
    }
    bool check(double mid){
        init();
        for(int i=1;i<=m;i++)
            add(xx[i],yy[i],min(zz[i],mid));
        double tmp=flow();
        return Ans-tmp<eps;
    }
    int main(){
        init(),scanf("%d%d%d",&n,&m,&p);
        for(int i=1;i<=m;i++)
            scanf("%d%d%lf",&xx[i],&yy[i],&zz[i]),add(xx[i],yy[i],zz[i]);
        Ans=r=flow();
        while(r-l>eps){
            double mid=(l+r)/2;
            if(check(mid))r=mid;
            else l=mid;
        }
        printf("%d
    %lf
    ",(int)Ans,l*p);
    }
    /*
    7 9 1
    1 2 3
    1 3 3
    2 3 3
    3 4 2
    3 5 2
    3 6 1
    4 7 2
    5 7 2
    6 7 2
    
    */

    这里写图片描述

  • 相关阅读:
    谷歌 colab调用 Kaggle 数据集
    TensorFlow/Keras binary_crossentropy损失函数
    R语言 pivot_longer 图表变换
    R语言 ggplot2 柱状图
    R语言 ggplot2 笔记
    Bash 批量删除指定后缀的文件
    MacBook 风扇控制软件 Macs Fan Control
    R语言 dplyr selec 辅助函数
    R语言一次性更新全部packages
    R语言 glue 版本冲突
  • 原文地址:https://www.cnblogs.com/SiriusRen/p/6532112.html
Copyright © 2011-2022 走看看