Taxi Cab Scheme

Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 712 Accepted Submission(s): 337

Problem 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
#include<stdio.h>
#include<string.h>
struct nn
{
int st,endt;
int x1,y1,x2,y2;
}node[505];
int vist[505],match[505],map[505][505],M;
int find(int i)
{
for(int j=1;j<=M;j++)
if(vist[j]==0&&map[i][j])
{
vist[j]=1;
if(match[j]==0||find(match[j]))
{
match[j]=i; return 1;
}
}
return 0;
}
int abs(int a)
{
return a>0?a:-a;
}
int main()
{
int t,h,f;
scanf("%d",&t);
while(t--)
{
scanf("%d",&M);
for(int i=1;i<=M;i++)
{
scanf("%d:%d %d%d%d%d",&h,&f,&node[i].x1,&node[i].y1,&node[i].x2,&node[i].y2);
node[i].st=h*60+f;
node[i].endt=node[i].st+abs(node[i].x1-node[i].x2)+abs(node[i].y1-node[i].y2);
}
memset(map,0,sizeof(map));
for(int i=1;i<=M;i++)
for(int j=1;j<=M;j++)
if(j!=i&&node[i].endt+abs(node[j].x1-node[i].x2)+abs(node[j].y1-node[i].y2)<node[j].st)
map[i][j]=1;
int ans=0;
memset(match,0,sizeof(match));
for(int i=1;i<=M;i++)
{
memset(vist,0,sizeof(vist));
ans+=find(i);
}
printf("%d\n",M-ans);
}
}

hdu1350Taxi Cab Scheme (最小路径覆盖)的更多相关文章

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

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

  2. UVaLive 3126 Taxi Cab Scheme (最小路径覆盖)

    题意:有 n 个客人,要从 si 到 ti,每个人有一个出发时间,现在让你安排最少和出租车去接,在接客人时至少要提前一分钟到达客人的出发地点. 析:把每个客人看成一个结点,然后如果用同一个出租车接的话 ...

  3. UVALive3126 Taxi Cab Scheme —— 最小路径覆盖

    题目链接:https://vjudge.net/problem/UVALive-3126 题解: 最小路径覆盖:即在图中找出尽量少的路径,使得每个结点恰好只存在于一条路径上.其中单独一个点也可以是一条 ...

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

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

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

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

  6. POJ:2060-Taxi Cab Scheme(最小路径覆盖)

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

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

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

  8. Taxi Cab Scheme POJ - 2060 二分图最小路径覆盖

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

  9. UVAlive3126 Taxi Cab Scheme(DAG的最小路径覆盖)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=32568 [思路] DAG的最小路径覆盖. 将每个人看做一个结点,如 ...

随机推荐

  1. 【POJ 3784】 Running Median (对顶堆)

    Running Median Description For this problem, you will write a program that reads in a sequence of 32 ...

  2. Struts2与Servlet之间的关系

    在struts2.0中,可以通过ServletActionContext.getRequest()获取request对象. 在action的方法中return一个字符串,该字符串对应struts.xm ...

  3. 【Matrix-tree定理】【并查集】【kruscal算法】bzoj1016 [JSOI2008]最小生成树计数

    题意:求一个图的最小生成树个数. 矩阵树定理:一张无向图的生成树个数 = (度数矩阵 - 邻接矩阵)的任意一个n-1主子式的值. 度数矩阵除了对角线上D[i][i]为i的度数(不计自环)外,其他位置是 ...

  4. python基础之序列化 time random os

    序列化与反序列化 json  pickle 1.什么是序列化与反序列化? 序列化就是将内存中的数据结构转成一种中间格式储存到硬盘或者基于网络传输 反序列化是网络,硬盘将被序列化的对象重新读到内存 2. ...

  5. C++ Any 任意基础类型封装

    下面是本人使用C++封装的一个针对任意基础类型以及用户自定义类型指针的通用类型.目的是为方便常用类型使用统一化及便利化.该类型的使用就与平时使用基础类型基本没什么差别.具体可参看以下代码及测试代码. ...

  6. CentOS 6.9下双网卡绑定单个IP地址及装网卡绑定到一个网桥(转)

    说明:经过查阅,原来双网卡绑定一个IP的专业名词叫做bond,可以实现负载均衡:如果想要实现两张网卡绑定到一个网桥,基本思路是两张网卡设置同一个网桥是行不通的,但如果先实现bond,然后将bond绑定 ...

  7. dns问题,QQ打得开,网页打不开

    dns问题,QQ打得开,网页打不开 ip4 dns 改为114.114.114.114. 原因有可能是路由出错之类的.114是默认的通用ip

  8. TJSONTableObject跨平台解析JSON

    TJSONTableObject跨平台解析JSON USES SynCrossPlatformJSON TSQLRecordPeoplePersistent = class(TPersistent) ...

  9. Linux下启动和停止Java应用程序的Shell脚本

    转自:http://blog.csdn.net/jadyer/article/details/7960802 资料参考来源自兔大侠,并略作修改:http://www.tudaxia.com/archi ...

  10. go语言基础之开发工具

    一.安装go 1.在linux环境下安装go yum install go -y 2.go下载地址 https://golang.org/dl/ 3.windows安装版本 go1.9.2.windo ...