TOJ 1023 Taxi Cab Scheme
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
把每一次的路途(起点-终点)看成一个结点的话。如果一辆出租车能够完成两两路途,就表示两个结点之间存在匹配。
如果建的图是无向图:
最小路径覆盖=结点数-最大匹配数/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的更多相关文章
- 【HDU1960】Taxi Cab Scheme(最小路径覆盖)
Taxi Cab Scheme Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- poj 2060 Taxi Cab Scheme (二分匹配)
Taxi Cab Scheme Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 5710 Accepted: 2393 D ...
- poj 2060 Taxi Cab Scheme (最小路径覆盖)
http://poj.org/problem?id=2060 Taxi Cab Scheme Time Limit: 1000MS Memory Limit: 30000K Total Submi ...
- Taxi Cab Scheme POJ && HDU
Online Judge Problem Set Authors Online Contests User Web Board Home Page F.A.Qs Statistical Charts ...
- 二分图最小路径覆盖--poj2060 Taxi Cab Scheme
Taxi Cab Scheme 时间限制: 1 Sec 内存限制: 64 MB 题目描述 Running a taxi station is not all that simple. Apart f ...
- Taxi Cab Scheme UVALive - 3126 最小路径覆盖解法(必须是DAG,有向无环图) = 结点数-最大匹配
/** 题目:Taxi Cab Scheme UVALive - 3126 最小路径覆盖解法(必须是DAG,有向无环图) = 结点数-最大匹配 链接:https://vjudge.net/proble ...
- UVA 1201 - Taxi Cab Scheme(二分图匹配+最小路径覆盖)
UVA 1201 - Taxi Cab Scheme 题目链接 题意:给定一些乘客.每一个乘客须要一个出租车,有一个起始时刻,起点,终点,行走路程为曼哈顿距离,每辆出租车必须在乘客一分钟之前到达.问最 ...
- HDU 1350 Taxi Cab Scheme
Taxi Cab Scheme Time Limit: 10000ms Memory Limit: 32768KB This problem will be judged on HDU. Origin ...
- poj2060——Taxi Cab Scheme(最小路径覆盖)
Description Running a taxi station is not all that simple. Apart from the obvious demand for a centr ...
随机推荐
- 排序算法汇总(java实现,附源代码)
整理系统的时候发现了原来写的各种算法的总结,看了一下,大吃一惊,那时候的我还如此用心,具体的算法,有的已经模糊甚至忘记了,看的时候就把内容整理出来,顺便在熟悉一下,以后需要的时候就可以直接过来摘抄了. ...
- 数值限制------c++程序设计原理与实践(进阶篇)
每种c++的实现都在<limits>.<climits>.<limits.h>和<float.h>中指明了内置类型的属性,因此程序员可以利用这些属性来检 ...
- F题(水题)
给出一个有N个数的序列,编号0 - N - 1.进行Q次查询,查询编号i至j的所有数中,最大的数是多少. 例如: 1 7 6 3 1.i = 1, j = 3,对应的数为7 6 3,最大的数为7. ...
- 【bzoj3998】弦论 后缀自动机
Description 对于一个给定长度为N的字符串,求它的第K小子串是什么. Input 第一行是一个仅由小写英文字母构成的字符串S 第二行为两个整数T和K,T为0则表示不同位置的相同子串算作一个. ...
- 洛谷P2764 最小路径覆盖问题(最大流)
传送门 先说做法:把原图拆成一个二分图,每一个点被拆成$A_i,B_i$,若原图中存在边$(u,v)$,则连边$(A_u,B_v)$,然后$S$对所有$A$连边,所有$B$对$T$连边,然后跑一个最大 ...
- centos6.3安装 jdk-8u131-linux-x64.gz
解压指令为:tar -zxvf jdk-8u131-linux-x64.gz 设置环境变量,首先是打开设置环境变量的文件夹,指令为:vi /etc/profile 然后在英文输入法下切换到“插 ...
- pycharm 2016 注册(pycharm-professional-2016.3.2)
BIG3CLIK6F-eyJsaWNlbnNlSWQiOiJCSUczQ0xJSzZGIiwibGljZW5zZWVOYW1lIjoibGFuIHl1IiwiYXNzaWduZWVOYW1lIjoiI ...
- SpringMVC返回JSON数据
1.导入json的jar包2.在Controller类中添加 //查看用户信息 ?json //params="json"的意思是访问view这个方法的时候,必须有一个参数json ...
- 伪元素改变date类型input框的默认样式实例页面
CSS代码: ::-webkit-datetime-edit { padding: 1px; background: url(/study/image/selection.gif); } ::-web ...
- 快速排序(一) 思想 JAVA实现
已知数组59.71.37.56.88.96.21.58.48.43 采用快速排序将数组有序. 快速排序同样采用了“分治策略”,使用递归的思路来实现算法. 快速排序的算法思想: 9.71.37.56.8 ...