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 ...
随机推荐
- 所谓IIS未注册引起的故障及解决
- windows环境下安装ZooKeeper
$.说明 ZooKeeper: ZooKeeper是一个分布式的,开放源码的分布式应用程序协调服务,是Google的Chubby一个开源的实现,是Hadoop和Hbase的重要组件. 它是一个为分布式 ...
- C语言#include的用法
1.#include 命令介绍 #include 命令是预处理命令的一种,预处理命令可以将别的源代码内容插入到所指定的位置:可以标识出只有在特定条件下才会被编译的某一段程序代码: 可以定义类似标识符功 ...
- NSRange 范围
前言 结构体,这个结构体用来表示事物的一个范围,通常是字符串里的字符范围或者集合里的元素范围. typedef struct _NSRange { NSUInteger location; // 表示 ...
- spring boot 自签发https证书
一.使用Jdk自带的工具生成数字证书,如下: Java代码 ./keytool -genkey -v -alias tomcat -keyalg RSA -keystore /root/tomca ...
- Day 4 上午
内容提要 进制转换 高精度 数论:筛法,gcd/exgcd,逆元 进制转换 10=2^3+2^0=1010(2)10=3^2+3^0=101(3) 10进制x-->k进制:短除法 k进制x--& ...
- kibana安装汉化包
kibana安装汉化包其实很简单!但要找到汉化包可能就很麻烦了.我这里提供了6.2的版本的汉化包!至于能不能在其他版本用,我就没试过了.但6.2的kibana本人亲测.没问题!!!! 下载——解压.这 ...
- 【算法笔记】B1042 字符统计
1042 字符统计 (20 分) 请编写程序,找出一段给定文字中出现最频繁的那个英文字母. 输入格式: 输入在一行中给出一个长度不超过 1000 的字符串.字符串由 ASCII 码表中任意可见字符及空 ...
- 网络寻路(思维+vector的应用)-----------蓝桥备战系列
标题:网络寻路 X 国的一个网络使用若干条线路连接若干个节点.节点间的通信是双向的.某重要数据包,为了安全起见,必须恰好被转发两次到达目的地.该包可能在任意一个节点产生,我们需要知道该网络中一共有多少 ...
- codeforces833B The Bakery
题面传送门 题目大意:将一个长度为n的序列分为k段,使得总价值最大,一段区间的价值表示为区间内不同数字的个数 思路: 显然的dp. 先想到一个朴素的状态转移方程 $dp[i][k]=max(dp[j] ...