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. android 线程间通信

    韩梦飞沙  韩亚飞  313134555@qq.com  yue31313  han_meng_fei_sha 1,共享内存 变量 2,文件,数据库 3,处理器 消息机制 4, 线程 的 等待,通知 ...

  2. [BZOJ2007][NOI2010]海拔(对偶图最短路)

    首先确定所有点的海拔非0即1,问题转化成裸的平面图最小割问题,进而转化成对偶图最短路(同BZOJ1002). 这题的边是有向的,所以所有边顺时针旋转90度即可. 如下图(S和T的位置是反的). #in ...

  3. Problem B: 指针:调用自定义交换函数,完成5个浮点数从小到大排列

    #include<stdio.h> int swap(float *p1,float *p2) { float flag; if(*p1>*p2) { flag=*p1; *p1=* ...

  4. Very Good!——C语言初学者百题大战之二

    #include<stdio.h> int main() { printf("***************\n\n Very Good!\n\n***************& ...

  5. CentOS 6.9下配置安装KVM

    注意:KVM一切安装和运行都是在root用户下完成的,并且只有root才能支持某些软件. 一.准备工作: 1.查看系统版本.内核版本 ##查看系统版本 # cat /etc/redhat-releas ...

  6. Java字符串格式化输入({0}/%s)

    用法: System.out.println(MessageFormat.format("{0}{1}",1,2)); System.out.println(String.form ...

  7. edittext 手机号、邮箱输入限制

      package com.example.yanlei.myapplication; import android.support.v7.app.AppCompatActivity;import a ...

  8. 【web.xml】报错java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener

    今天搭建新的项目,虽然在web.xml中配置了ContextLoaderListener以及IntrospectorCleanupListener 如下: web.xml中部分代码: <!-- ...

  9. Scut快速开发

    1     开发环境 Scut Lib版本:5.2.3.2 需要安装的软件 a)        IIS和消息队列(MSMQ) b)        数据库,Sql2005以上版本 c)        V ...

  10. UINavigationController 详解

    // 导航控制器 // 1. 比较常用的视图控制器管理类 // 2. 以栈的形式管理视图控制器, 先进后出 // 3. 创建navigation后, 视图控制器上会多出一个导航栏 // 4. 导航栏高 ...