ZOJ3156_Taxi (bipartite graph/Bipartite Graph)
Solution report
Question:
N people, m vehicles, coordinates of people and vehicles, and the speed of people, and the minimum time for all people to get on the bus. (A car can only be one person)
Ideas:
The original thought that the minimum time in the bipartite graph became the best match for the bipartite graph. In fact, the time can be divided into two parts to meet the time of the person and the car line diagram, so that the minimum time of the Binary Graph is obtained.
It may have been a drop in writing. I actually did this for two minutes, sad
In fact, you only need to save all the possible time in the binary time faster.
#include
#include
#include
#include
#define N 1000#define M 1000#define inf 99999999using namespace std;int n,m,mmap[N][N],vis[N],pre[N];struct point{ double x,y;} g[N],h[N];double _time[110][110];double dis(point p1,point p2){ return sqrt((p2.x-p1.x)*(p2.x-p1.x)+(p2.y-p1.y)*(p2.y-p1.y));}int dfs(int x){ for(int i=1; i<=m; i++) { if(!vis[i]&&mmap[x][i]) { vis[i]=1; if(pre[i]==-1||dfs(pre[i])) { pre[i]=x; return 1; } } } return 0;}int main(){ int i,j; double v; while(~scanf("%d%d",&n,&m)) { memset(mmap,0,sizeof(mmap)); for(i=1; i<=n; i++) { scanf("%lf%lf",&g[i].x,&g[i].y); } for(i=1; i<=m; i++) { scanf("%lf%lf",&h[i].x,&h[i].y); } scanf("%lf",&v); double tmax=-1; for(i=1; i<=n; i++) { for(j=1; j<=m; j++) { _time[i][j]=dis(g[i],h[j])/v; if(_time[i][j]>tmax) { tmax=_time[i][j]; } } } double l=0,r=tmax; double minn=0; while(l<=r) { double mid=(l+r)/2; for(i=1; i<=n; i++) { for(j=1; j<=m; j++) { if(_time[i][j]<=mid) mmap[i][j]=1; else mmap[i][j]=0; } } int ans=0; memset(pre,-1,sizeof(pre)); for(i=1; i<=n; i++) { memset(vis,0,sizeof(vis)); ans+=dfs(i); } if(ans>=n) { minn=mid; r=mid-0.00001; } else { l=mid+0.00001; } } printf("%.2lf\n",minn); } return 0;}