poj3308

Posted gaudar

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了poj3308相关的知识,希望对你有一定的参考价值。

边加错了。正反加为INF了。

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <cassert>
#include <stack>
#include <bitset>
//#include <unordered_set>
#define mkp make_pair
#define err cout<<"here"<<endl
using namespace std;
const double EPS=1e-12;
typedef long long lon;
typedef pair<int,int> pii;
typedef unsigned long long ull;
typedef map<ull,int>::iterator IT;
const lon SZ=5900,SSZ=9000010,APB=3000010,mod=100000,one=97;
const lon INF=0x3f3f3f3f3f3f3f3f;
lon n,m,knum,S=5707,T=5708;
struct nd{
    lon to,wt;
    nd(lon a=0,lon b=0):to(a),wt(b){}
};
lon dep[SZ];
lon head[SZ],nex[SSZ],to[SSZ];
double wt[SSZ];
lon cnt=-1;

void add(lon u,lon v,double w)
{
    ++cnt;
    nex[cnt]=head[u];
    head[u]=cnt;
    to[cnt]=v,wt[cnt]=w;
}

bool bfs()
{
    memset(dep,0,sizeof(dep));
    queue<lon> q;
    q.push(S);
    dep[S]=1;
    for(;q.size();)
    {
        lon fr=q.front();
        q.pop();
        for(lon i=head[fr];i!=-1;i=nex[i])
        {
            lon t=to[i];
            double w=wt[i];
            if(w>EPS&&!dep[t])
            {
                dep[t]=dep[fr]+1;
                q.push(t);
            }
        }
    }
    return dep[T];
}

double dinic(lon x,double flow)
{
    if(x==T)return flow;
    else
    {
        double rem=flow;
            for(lon i=head[x];i!=-1&&rem>EPS;i=nex[i])
            {
                
                lon t=to[i];
                double w=wt[i];
                if(dep[t]!=dep[x]+1||w<EPS)continue;
                double tmp=dinic(t,min(rem,w));
                if(tmp<EPS)dep[t]=0;
                wt[i]-=tmp;
                wt[i^1]+=tmp;
                rem-=tmp;
            }
        return flow-rem;
    }
}

void init()
{
    cin>>n>>m>>knum;
    memset(head,-1,sizeof(head));
    cnt=-1;
    for(int i=1;i<=n;++i)
    {
        double tmp;
        cin>>tmp;
        add(S,i,log2(tmp));
        add(i,S,log2(tmp));
    }
    for(int i=1;i<=m;++i)
    {
        double tmp;
        cin>>tmp;
        //err;
        add(i+n,T,log2(tmp));
        add(T,i+n,log2(tmp));
    }
    for(int i=1;i<=knum;++i)
    {
        int a,b;
        cin>>a>>b;
        add(a,b+n,log2(INF));
        add(b+n,a,0);
    }
    double res=0;
    for(;bfs();res+=dinic(S,log2(INF)));
    cout<<fixed<<setprecision(4)<<pow(2,res)<<endl;
}

void work()
{
    
}

void release()
{    
    
}

int main()
{
    std::ios::sync_with_stdio(0);
    //freopen("d:\\1.txt","r",stdin);
    lon casenum;
    cin>>casenum;
    //cout<<casenum<<endl;
    for(lon time=1;time<=casenum;++time)
    //for(lon time=1;cin>>n>>m>>S>>T,n;++time)
    {
        init();
        work();
        release();
    }
    return 0;
}

 

以上是关于poj3308的主要内容,如果未能解决你的问题,请参考以下文章

poj 3308 Paratroopers(最小点权覆盖)

poj 3308 Paratroopers 最小割 最小点权覆盖

POJ3308 Paratroopers(网络流)(最小割)

POJ 3308 最少点集覆盖

poj3308 Paratroopers --- 最小点权覆盖-&gt;最小割

POJ2778DNA Sequence(AC自动机)