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. C# 修改配置文件

    /// <summary> /// 保存配置文件的设定 /// </summary> /// <param name="Key"></pa ...

  2. c#中取绝对值

    记一次工作中查询的资料: System.Math.Abs(float value); System.Math.Abs(decimal value); System.Math.Abs(int value ...

  3. python3 对list对象的增删改查

    class peoples: people_list =[] class people: name='' age=-1 def __init__(self,name,age): self.name = ...

  4. MySQL学习——存储引擎

    MySQL学习——存储引擎 摘要:本文主要学习了MySQL数据库的存储引擎. 什么是存储引擎 数据库存储引擎是数据库底层软件组件,数据库管理系统使用数据引擎进行创建.查询.更新和删除数据操作.不同的存 ...

  5. DataGridView中的rows.Count比实际行数多1的原因以及解决办法

    场景 DataGridView怎样实现添加.删除.上移.下移一行: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/10281414 ...

  6. [转]RHEL7上配置NFS服务

    原文地址:http://380531251.blog.51cto.com/7297595/1659865 1.课程目标 了解什么是NFS及其功能: 掌握NFS的配置: 掌握NFS的验证: 能够单独熟练 ...

  7. 从立创EDA,Gratipay看中文编程开发环境和推广运营的一个趋势

    前不久听说立创EDA,对比之前的讨论: 适合中文用户的编程语言和IDE, 侧重于现有语言/IDE不具备的特性 · Issue #11 · program-in-chinese/overview,觉得颇 ...

  8. 洛谷P2260 [清华集训2012]模积和(容斥+数论分块)

    题意 https://www.luogu.com.cn/problem/P2260 思路 具体思路见下图: 注意这个模数不是质数,不能用快速幂来求逆元,要用扩展gcd. 代码 #include< ...

  9. KMP算法计算next值和nextVal值

    KMP算法: 给定一个主串S及一个模式串P,判断模式串是否为主串的子串:若是,返回匹配的第一个元素的位置(序号从1开始),否则返回0: 这里先不写算法,仅仅计算next和nextVal值 那么计算时只 ...

  10. Html学习之十八(表格与表单学习--统计表制作)

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...