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存储模型(十三)
概述 Java存储模型(JMM),安全发布.规约,同步策略等等的安全性得益于JMM,在你理解了为什么这些机制会如此工作后,可以更容易有效地使用它们. 1. 什么是存储模型,要它何用. 如果缺少同步,就 ...
- [转]B+Tree图解
一, M阶B+树的定义(M阶是指一个节点最多能拥有的孩子数,M>2): 图1.1 3阶B+树 (1)根结点只有1个,分支数量范围[2,m]. (2)除根以外的非叶子结点,每个结点包含分支数 ...
- 201621123012 《Java程序设计》第1周学习总结
1. 本章学习总结 学习了java的理论知识和它与C语言的差别,什么是JVM,区分JRE与JDK并学习JAVA环境的安装.熟悉控制台下的常用命令,java函数的编写.熟练使用编写JAVA所需要的工具( ...
- django 重写User表增加字段设置
models中: from django.contrib.auth.models import AbstractUser lass User(AbstractUser): mobile = model ...
- CI框架部署后访问出现404
昨天新配置了一个PHP集成开发环境,安装完后,把项目放到Apache服务器的www目录下,发现只能打开首页,其他页面全部无法打开,当时比较纳闷,以为是服务器没有配置好,测试了一下,发现环境配置没有问题 ...
- P3596 [POI2015]MOD
$ \color{#0066ff}{ 题目描述 }$ 给定一棵无根树,边权都是1,请去掉一条边并加上一条新边,定义直径为最远的两个点的距离,请输出所有可能的新树的直径的最小值和最大值 \(\color ...
- Zookeeper客户端对比选择_4
Zookeeper客户端对比选择 本文思维导图 使用框架的好处是自带一套实用的API,但是Zookeeper虽然非常强大,但是社区却安静的可怕,版本更新较慢,下面会先从zookeeper原生API的不 ...
- 使用C#来编写一个异步的Socket服务器
介绍 我最近需要为一个.net项目准备一个内部线程通信机制. 项目有多个使用ASP.NET,Windows 表单和控制台应用程序的服务器和客户端构成. 考虑到实现的可能性,我下定决心要使用原生的soc ...
- gym 102082B dp
和51nod1055 一样: #include<iostream> #include<cstdio> #include<algorithm> #include< ...
- 分布式中为什么要加入redis缓存的理解
面我们介绍了mybatis自带的二级缓存,但是这个缓存是单服务器工作,无法实现分布式缓存.那么什么是分布式缓存呢?假设现在有两个服务器1和2,用户访问的时候访问了1服务器,查询后的缓存就会放在1服务器 ...