Description

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.
For the
sake of simplicity, we model a city as a rectangular grid. An address in
the city is denoted by two integers: the street and avenue number. The
time needed to get from the address a, b to c, d by taxi is |a - c| + |b
- d| minutes. A cab may carry out a booked ride if it is its first ride
of the day, or if it can get to the source address of the new ride from
its latest,at least one minute before the new ride's scheduled
departure. Note that some rides may end after midnight.

Input

On
the first line of the input is a single positive integer N, telling the
number of test scenarios to follow. Each scenario begins with a line
containing an integer M, 0 < M < 500, being the number of booked
taxi rides. The following M lines contain the rides. Each ride is
described by a departure time on the format hh:mm (ranging from 00:00 to
23:59), two integers a b that are the coordinates of the source address
and two integers c d that are the coordinates of the destination
address. All coordinates are at least 0 and strictly smaller than 200.
The booked rides in each scenario are sorted in order of increasing
departure time.

Output

For each scenario, output one line containing the minimum number of cabs required to carry out all the booked taxi rides.

Sample Input

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 11

Sample Output

1
2

Source

Northwestern Europe 2004

把每一次的路途(起点-终点)看成一个结点的话。如果一辆出租车能够完成两两路途,就表示两个结点之间存在匹配。

如果建的图是无向图:

最小路径覆盖=结点数-最大匹配数/2

如果建的是有向图:

最小路径覆盖=结点数-最大匹配数

 #include <stdio.h>
#include <string.h>
#include <math.h>
#define MAXN 550 int bmap[MAXN][MAXN];
bool bmask[MAXN];//寻找增广路径时的标志数组
int nx,ny;//nx左集合的顶点数目,ny为右集合的顶点数目
int cx[MAXN];//cx[i]表示左集合i顶点所匹配到的右集合的顶点序号
int cy[MAXN];//cy[i]表示右集合i顶点所匹配到的左集合的顶点序号 struct Node{
int bx,by,ex,ey;
int begin,end;
}nod[MAXN]; //寻找增广路径
int findpath(int u){
for(int i=; i<ny; i++){
//如果匹配,且i不在增广路上
if( bmap[u][i] && !bmask[i] ){
//把i加到增广路上
bmask[i]=;
//如果i是未盖点或者从i出发有增广路
if(cy[i]==- || findpath(cy[i])){
//修改对应的项为u,表示有增广路
cy[i]=u;
return ;
}
}
}
return ;
} int hungray(){
int res=;
for(int i=; i<nx; i++){
cx[i]=-;
}
for(int j=; j<ny; j++){
cy[j]=-;
}
for(int i=; i<nx; i++){
//如果从左边开始是未盖点的
if(cx[i]==-){
for(int j=; j<ny; j++){
bmask[j]=;
}
res+=findpath(i);
}
}
return res;
} int main()
{
int n,t;
int a,b,c,d;
int h,m;
scanf("%d",&t);
while( t-- ){
scanf("%d",&n);
nx=n;
ny=n;
for(int i=; i<n; i++){
scanf("%d:%d" ,&h ,&m);
scanf("%d %d %d %d" ,&a ,&b ,&c ,&d);
nod[i].bx=a;
nod[i].by=b;
nod[i].ex=c;
nod[i].ey=d;
nod[i].begin=*h+m;
nod[i].end=nod[i].begin+fabs(a-c)+fabs(b-d);
}
//建图
memset(bmap , ,sizeof(bmap));
for(int i=; i<n; i++){
for(int j=i+; j<n; j++){
int dis= fabs(nod[j].bx-nod[i].ex) + fabs(nod[j].by-nod[i].ey);
if( nod[i].end +dis < nod[j].begin ){
bmap[i][j]=;
}
}
}
int ans=hungray();
printf("%d\n",n-ans);
}
return ;
}

最新文章

  1. 在DCOM 中不存在WORD、EXCEL等OFFICE组件
  2. 学习SVG系列(1):SVG基础
  3. mvc2/3/4_伪静态_路由配置
  4. 简单回忆一下JavaScript中的数据类型
  5. Android——GridLayout
  6. oracle组件
  7. MVC中使用过滤器记录异常日志
  8. HTML5 canvas生成图片马赛克特效插件
  9. extjs_11_mvc模式
  10. 向MapReduce转换:生成用户向量
  11. HAproxy负载均衡
  12. 关于SharePoint2007简单随感
  13. 自定义MVC实现登录案例
  14. linux学习问题总结
  15. PyQt--QTreeWidget
  16. [转]系统架构演变--集中式架构-垂直拆分-分布式服务-SOA(服务治理)-微服务
  17. 保存 laravel model 而不更新 timestamps 的方法
  18. VS2010 正在创建“Debug\test2.unsuccessfulbuild”,因为已指定“AlwaysCreate”。
  19. prime docker-compose 环境运行试用
  20. OLAP和OLTP的区别

热门文章

  1. Android之AlterDialog介绍
  2. 在普通的&quot;类库&quot;项目中添加 WPF 的 Window 对象
  3. C#在线运行--cmd方法
  4. java 实验2 类
  5. VS2017+DLib_19.17详细配置教程
  6. Deploy Flask app to Apache on Windows
  7. JQ模拟触发事件
  8. 利用EFCore 封装Repository(可扩展不同数据的sql操作)
  9. 瀑布模型,(增量开发)渐增式开发,原型化开发,统一过程模型(RUP)
  10. hexo 博客