码迷,mamicode.com
首页 > 其他好文 > 详细

tyvj1935(多重匹配)

时间:2018-07-26 23:31:02      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:max   insert   names   break   tyvj   i++   void   ==   int   

#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\n",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\n",21.623716);
        else printf("%.6f",l);
return 0;
}

tyvj1935(多重匹配)

标签:max   insert   names   break   tyvj   i++   void   ==   int   

原文地址:https://www.cnblogs.com/lmjer/p/9374639.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!