zzuli1672–二分答案+最大匹配

來源:互聯網
上載者:User
#include<stdio.h>#include<math.h>#include<string.h>#define max 110int xx[max],yy[max];int v[max*max][max];double map[max*max][max];int pi[max];int fang[max];int m,n,t1,t2,s;double dis(int x1,int y1,int x2,int y2){return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));}int dfs(int i){for(int j=1;j<=m;j++){if(fang[j]==0&&v[i][j]==1){fang[j]=1;if(pi[j]==0||dfs(pi[j])){pi[j]=i;return 1;}}}return 0;}int fun(double h){int i,j,p;for(i=1;i<=m*n;i++)for(j=1;j<=m;j++){if(map[i][j]<=h)v[i][j]=1;else v[i][j]=0;}p=0;memset(pi,0,sizeof(pi));for(i=1;i<=m*n;i++){memset(fang,0,sizeof(fang));if(dfs(i))p++;}if(p==m)return 1;else return 0;}int main(){int i,j,k;double x,y,anss,mid;while(scanf("%d%d%d%d%d",&n,&m,&t1,&t2,&s)!=EOF){for(i=1;i<=m+n;i++)scanf("%d%d",&xx[i],&yy[i]);memset(map,0,sizeof(map));for(i=1;i<=n;i++)for(j=1;j<=m;j++)for(k=1;k<=m;k++)map[(i-1)*m+j][k]=(t1*1.0/60)*j+t2*(j-1)+dis(xx[k],yy[k],xx[m+i],yy[m+i])/s;x=0;y=200000000;anss=200000000;while(fabs(x-y)>1e-8){mid=(x+y)/2;if(fun(mid)){y=mid;anss=mid;}else x=mid;}printf("%.6f\n",anss);}return 0;}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.