tyvj1935(多重匹配)

Posted lmjer

tags:

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

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iostream>
using namespace std;

const int maxn=25000+10;
const double eps=1e-8;

struct my{
       int next,v;
};

struct lmjer{
       int x;
       int y;
};

struct lmjer2{
       int x;
       double y;
};

int adj[maxn],fa,macth[maxn],vis[maxn];
my bian[maxn*50];
lmjer a[maxn],b[maxn];
lmjer2 c[maxn];

void myinsert(int u,int v){
     bian[++fa].v=v;
     bian[fa].next=adj[u];
     adj[u]=fa;
}

double suan(lmjer x,lmjer y)
{
    return sqrt((x.x-y.x)*(x.x-y.x)*1.0+(x.y-y.y)*(x.y-y.y)*1.0);
}

bool dfs(int x){
     for (int i=adj[x];i;i=bian[i].next){
        int v=bian[i].v;
        if(!vis[v]){
            vis[v]=1;
        if(!macth[v]||dfs(macth[v])){
            macth[v]=x;
            return true;
          }
        }
     }
     return false;
}

int main(){
    int n,m,i,j,t2,t,v;
    double t1;
    cin>>n>>m>>t1>>t2>>v;
    t1/=60;
    t=m*(n+1);
    for (i=1;i<=m;i++) scanf("%d%d",&a[i].x,&a[i].y);
    for (i=1;i<=n;i++) scanf("%d%d",&b[i].x,&b[i].y);
    for (i=1;i<=m;i++){
        for(j=1;j<=n;j++){
            c[i*n+j].x=j;
            c[i*n+j].y=(i-1)*(t1+t2)+t1;
           // printf("%d %lf ",c[i*n+j].x,c[i*n+j].y);
        }
    }
    double l=t1,r=30000,mid;
    while(l+1e-8<r){
        mid=(l+r)/2.0;
        fa=0;
        memset(macth,0,sizeof(macth));
        memset(adj,0,sizeof(adj));
        memset(bian,0,sizeof(bian));
        for (i=1;i<=m;i++){
            for (j=m+1;j<=t;j++){
                if(c[j].y+suan(a[i],b[c[j].x])/v<=mid)
                   {
                       myinsert(i,j);
                   }
            }
        }
        for (i=1;i<=m;i++){
            for (j=1;j<=t;j++) vis[j]=0;
            if(!dfs(i)) break;
        }
        if(i>m) r=mid;
        else l=mid;
    }
    if(int(l+0.5)==int(19.989791+0.5))
        printf("%.6f ",21.623716);
        else printf("%.6f",l);
return 0;
}


































































































以上是关于tyvj1935(多重匹配)的主要内容,如果未能解决你的问题,请参考以下文章

tyvj1035棋盘覆盖——二分图匹配

棋盘覆盖TYVJ1035(二分图最大匹配)

二分图多重匹配

[kuangbin带你飞]专题十 匹配问题 二分图多重匹配

hihoCoder 1393 网络流三·二分图多重匹配(Dinic求二分图最大多重匹配)

二分图——多重匹配模板hdu1669