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

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<cstdio>
#include<cstring>
#include<math.h>
using namespace std;
int N;
int line[][];
int g[],used[];
struct Node{
int t,h,m,a,b,c,d;
}node[];
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+<=fabs(A.t-B.t)?:;
}
bool found(int x)
{
for(int i=;i<=N;i++) {
if(line[x][i]&&!used[i]) {
used[i]=;
if(g[i]==-||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,,sizeof(line));
memset(g,-,sizeof(g));
for(int i=;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*+node[i].m;
}
for(int i=;i<=N;i++) {
for(int j=i+;j<=N;j++) {
line[i][j]=is_link(node[i],node[j]);
}
}
int ans=N;
for(int i=;i<=N;i++) {
memset(used,,sizeof(used));
if(found(i)) ans--;
}
printf("%d\n",ans);
}
return ;
}

Taxi Cab Scheme POJ - 2060 二分图最小路径覆盖的更多相关文章

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

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

  2. UVALive-3126 Taxi Cab Scheme (DAG的最小路径覆盖)

    题目大意:要给n个人安排车,已知每个人的出发时间和起点与终点,问最少需要安排几辆车才能完成任务. 题目分析:最小路径覆盖.如果送完a到目的地后能在b出发之前赶来接b,那么连一条有向边a->b,最 ...

  3. POJ 3020 (二分图+最小路径覆盖)

    题目链接:http://poj.org/problem?id=3020 题目大意:读入一张地图.其中地图中圈圈代表可以布置卫星的空地.*号代表要覆盖的建筑物.一个卫星的覆盖范围是其周围上下左右四个点. ...

  4. [bzoj2150]部落战争_二分图最小路径覆盖

    部落战争 bzoj-2150 题目大意:题目链接. 注释:略. 想法: 显然是最小路径覆盖,我们知道:二分图最小路径覆盖等于节点总数-最大匹配. 所以我们用匈牙利或者dinic跑出最大匹配,然后用总结 ...

  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 POJ && HDU

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

  7. POJ 3020 Antenna Placement (二分图最小路径覆盖)

    <题目链接> 题目大意:一个矩形中,有N个城市’*’,现在这n个城市都要覆盖无线,每放置一个基站,至多可以覆盖相邻的两个城市.问至少放置多少个基站才能使得所有的城市都覆盖无线? 解题分析: ...

  8. 【HDU3861 强连通分量缩点+二分图最小路径覆盖】

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3861 题目大意:一个有向图,让你按规则划分区域,要求划分的区域数最少. 规则如下:1.有边u到v以及有 ...

  9. hdu 1151 Air Raid(二分图最小路径覆盖)

    http://acm.hdu.edu.cn/showproblem.php?pid=1151 Air Raid Time Limit: 1000MS   Memory Limit: 10000K To ...

随机推荐

  1. Modbus RTU通信协议详解以及与Modbus TCP通信协议之间的区别和联系

    Modbus通信协议由Modicon公司(现已经为施耐德公司并购,成为其旗下的子品牌)于1979年发明的,是全球最早用于工业现场的总线规约.由于其免费公开发行,使用该协议的厂家无需缴纳任何费用,Mod ...

  2. python基础(20):序列化、json模块、pickle模块

    1. 序列化 什么叫序列化——将原本的字典.列表等内容转换成一个字符串的过程就叫做序列化. 1.1 为什么要有序列化 为什么要把其他数据类型转换成字符串?因为能够在网络上传输的只能是bytes,而能够 ...

  3. 完整版的CAD技巧!3天轻松玩转CAD,零基础也能学会

    最近有很多小伙伴反应,CAD图纸学起来有点小困难,也许你还没能掌握技巧,CAD大神带你3天轻松玩转CAD,零基础也能快速学会. 一.看懂图纸是关键 CAD制图首先得让自己知道要绘制什么,如果心中对图纸 ...

  4. RESTFul&HTTP GET简介

    RestApi:https://www.cnblogs.com/springyangwc/archive/2012/01/18/2325784.html RESTFul API设计指南:http:// ...

  5. SQLMAP之tamper详解

    sqlmap 是一款注入神器广为人知,里面的 tamper 常常用来绕过 WAF ,很实用的模块,但是却常常被新手忽略(比如我),今天就整理总结一下 tamper 的用法以及 tamper 的编写 P ...

  6. 【Servlet】JavaWeb应用的执行流程

    Tomcat与Servlet简介 Tomcat Tomcat是Apache 软件基金会(Apache Software Foundation)的Jakarta 项目中的一个核心项目,由Apache.S ...

  7. 【XML】XPath表达式

    XPath简介 XPath即为XML路径语言(XML Path Language),它是一种用来确定XML文档中某部分位置的语言. XPath基于XML的树状结构,提供在数据结构树中找寻节点的能力.起 ...

  8. mysql操作数据表

    目录 创建数据表 列约束 查看数据表结构 列类型(字段类型) 整型 浮点型 字符串 时间日期类型 Date Time Datetime Timestamp Year 枚举enum 修改表名 增加字段 ...

  9. Python—实现sftp客户端(连接远程服务器)

    使用SFTP上传与下载文件方式一: import paramiko transport = paramiko.Transport(("106.15.88.182", 22)) # ...

  10. Anaconda3使用

    1.使用conda安装各种包到指定路径下的环境, conda install --prefix=/home/xxx/PycharmProjects/project_01/env numpy 2.安装指 ...