Running a taxi station is not all that simple. Apart from the obvious demand for a centralised coordination of the cabs in order to pick up the customers calling to get a cab as soon as possible,there is also a need to schedule all the taxi rides which have been booked in advance.Given a list of all booked taxi rides for the next day, you want to minimise the number of cabs needed to carry out all of the rides.
2 2 08:00 10 11 9 16 08:07 9 16 10 11 2 08:00 10 11 9 16 08:06 9 16 10 11Sample Output
1 2
OJ-ID:
poj-2060
author:
Caution_X
date of submission:
20191002
tags:
二分图最小点覆盖
description modelling:
给定一个二维坐标图,从一个点a到另一个点b费时(a.x-b.x)+(a.y-b.y),现在有n个出租车订单,每个订单提供起点终点坐标和用车时间,问最少需要几辆出租车才可以在用车时间内接完所有客人
major steps to solve it:
(1) 假设我们派出了n辆出租车,如果两个订单恰好可以由一辆车完成,那么出租车数-1.
(2) 建图:现在以一辆车能否在接完这单并且及时接下下一单为依据建立一个二分图,如果两个订单可以由一辆车接下,那么这两个订单设定成匹配状态
(3) 算出最小路径覆盖(二分图最小路径覆盖:用最少的边覆盖所有的点)
最小路径覆盖=N-二分图最大匹配
AC code:
#include#include #include using namespace std; int N; int line[550][550]; int g[550],used[550]; struct Node{ int t,h,m,a,b,c,d; }node[550]; int is_link(Node A,Node B) { int dis1=fabs(A.a-A.c)+fabs(A.b-A.d); int dis2=fabs(B.a-A.c)+fabs(B.b-A.d); return dis1+dis2+1<=fabs(A.t-B.t)?1:0; } bool found(int x) { for(int i=1;i<=N;i++) { if(line[x][i]&&!used[i]) { used[i]=1; if(g[i]==-1||found(g[i])) { g[i]=x; return true; } } } return false; } int main() { //freopen("input.txt","r",stdin); int T; scanf("%d",&T); while(T--) { scanf("%d",&N); memset(line,0,sizeof(line)); memset(g,-1,sizeof(g)); for(int i=1;i<=N;i++) { int h,m,a,b,c,d; scanf("%d:%d %d %d %d %d",&node[i].h,&node[i].m,&node[i].a,&node[i].b,&node[i].c,&node[i].d); node[i].t=node[i].h*60+node[i].m; } for(int i=1;i<=N;i++) { for(int j=i+1;j<=N;j++) { line[i][j]=is_link(node[i],node[j]); } } int ans=N; for(int i=1;i<=N;i++) { memset(used,0,sizeof(used)); if(found(i)) ans--; } printf("%d\n",ans); } return 0; }