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 ;
}

TOJ 1023 Taxi Cab Scheme的更多相关文章

  1. 【HDU1960】Taxi Cab Scheme(最小路径覆盖)

    Taxi Cab Scheme Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  2. poj 2060 Taxi Cab Scheme (二分匹配)

    Taxi Cab Scheme Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 5710   Accepted: 2393 D ...

  3. poj 2060 Taxi Cab Scheme (最小路径覆盖)

    http://poj.org/problem?id=2060 Taxi Cab Scheme Time Limit: 1000MS   Memory Limit: 30000K Total Submi ...

  4. Taxi Cab Scheme POJ && HDU

    Online Judge Problem Set Authors Online Contests User Web Board Home Page F.A.Qs Statistical Charts ...

  5. 二分图最小路径覆盖--poj2060 Taxi Cab Scheme

    Taxi Cab Scheme 时间限制: 1 Sec  内存限制: 64 MB 题目描述 Running a taxi station is not all that simple. Apart f ...

  6. Taxi Cab Scheme UVALive - 3126 最小路径覆盖解法(必须是DAG,有向无环图) = 结点数-最大匹配

    /** 题目:Taxi Cab Scheme UVALive - 3126 最小路径覆盖解法(必须是DAG,有向无环图) = 结点数-最大匹配 链接:https://vjudge.net/proble ...

  7. UVA 1201 - Taxi Cab Scheme(二分图匹配+最小路径覆盖)

    UVA 1201 - Taxi Cab Scheme 题目链接 题意:给定一些乘客.每一个乘客须要一个出租车,有一个起始时刻,起点,终点,行走路程为曼哈顿距离,每辆出租车必须在乘客一分钟之前到达.问最 ...

  8. HDU 1350 Taxi Cab Scheme

    Taxi Cab Scheme Time Limit: 10000ms Memory Limit: 32768KB This problem will be judged on HDU. Origin ...

  9. poj2060——Taxi Cab Scheme(最小路径覆盖)

    Description Running a taxi station is not all that simple. Apart from the obvious demand for a centr ...

随机推荐

  1. 关于nosql的讲解

    Data Base  关于nosql的讲解 nosql非关系型数据库. 优点: 1.可扩展 2.大数据量,高性能 3.灵活的数据模型 4.高可用 缺点: 1.不正式 2.不标准 非关系型数据库有哪些: ...

  2. 个人常用Markdow语法代码备用

    1.分隔线 -------------------------------- 2.OC代码 ``` Objective-C ``` 3.字体加粗 ##加粗## 4.标题样式 <h1> &l ...

  3. PHP7 - MongoDB Driver 使用心得

    php7 只能使用Mongodb driver来驱动mongodb. 使用Mongodb Driver连接数据库 刚开始使用Mongodb Driver的时候我是拒绝的.查看官方文档只看到一排的类和不 ...

  4. golang文件处理函数openfile与linux系统的文件函数的耦合

    golang运行最理想的环境是linux系统中,编译速度和执行速度都比较快,本文是关于golang中的文件操作函数 在golang标准库中os包提供了不依赖平台的借口,但是使用的风格是unix风格的. ...

  5. Django rest framework框架——APIview源码分析

    一.什么是rest REST其实是一种组织Web服务的架构,而并不是我们想象的那样是实现Web服务的一种新的技术,更没有要求一定要使用HTTP.其目标是为了创建具有良好扩展性的分布式系统. 可用一句话 ...

  6. Python——可变和不可变类型数据

    什么是不可变类型? 存储空间保存的数据不允许被修改,这种数据就是不可变类型. 常见的不可变类型有: 数字类型 int, bool, float, complex, long(2.x) 字符串 str ...

  7. 【算法】关于图论中的最小生成树(Minimum Spanning Tree)详解

    本节纲要 什么是图(network) 什么是最小生成树 (minimum spanning tree) 最小生成树的算法 什么是图(network)? 这里的图当然不是我们日常说的图片或者地图.通常情 ...

  8. Phpstudy+DiscuzX安装详解

    1.下载Discuz,地址:https://gitee.com/ComsenzDiscuz/DiscuzX/repository/archive/master.zip 2.下载phpstudy 3.将 ...

  9. Python开发MapReduce系列(二)Python实现MapReduce分桶

    版权声明:本文为博主原创文章,未经博主允许不得转载   首先,先引出两点来展开下面的话题. (1)map阶段的排序是在hash之后,写入磁盘之前进行.排序的两个关键字是partition(分区编号)和 ...

  10. fork()父子进程文件描述符的关系

    父子进程共享文件描述符:此说法,其实是父子进程共享 文件表项(父进程和子进程共享同一个file table entry) 由于子进程是父进程的拷贝,子进程会拷贝父进程的进程描述符中的文件描述符表,可以 ...