poj 2060 Taxi Cab Scheme (二分匹配)

时间:2022-09-30 17:32:59
Taxi Cab Scheme
Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 5710   Accepted: 2393

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

二分匹配:

弄清楚题意比较重要:

出租车公司有n个预约, 每个预约有时间和地点, 地点分布在二维整数坐标系上, 地点之间的行驶时间为两点间的曼哈顿距离(|x1 - x2| + |y1 - y2|)。一辆车可以在运完一个乘客后运另一个乘客, 条件是此车要在预约开始前一分钟之前到达出发地, 问最少需要几辆车搞定所有预约。(摘自http://blog.sina.com.cn/s/blog_6635898a0100m54w.html)

我就是没弄清题意WA了好几次。弄清提议后开始构图,求最小边覆盖,还有就是这是有向图有所以构单边。

 //692K    79MS    C++    1333B    2014-06-05 11:26:44
#include<iostream>
#include<vector>
#define N 505
using namespace std;
struct node{
int a,b,c,d;
int time;
}p[N];
vector<int>V[N];
int match[N];
int vis[N];
int n;
int dfs(int u)
{
for(int i=;i<V[u].size();i++){
int v=V[u][i];
if(!vis[v]){
vis[v]=;
if(match[v]==- || dfs(match[v])){
match[v]=u;
return ;
}
}
}
return ;
}
int hungary()
{
int ret=;
memset(match,-,sizeof(match));
for(int i=;i<n;i++){
memset(vis,,sizeof(vis));
ret+=dfs(i);
}
return ret;
}
int main(void)
{
int t;
int time[N];
int dis[N];
int h,m;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(int i=;i<=n;i++) V[i].clear();
for(int i=;i<n;i++){
scanf("%d:%d %d%d%d%d",&h,&m,&p[i].a,&p[i].b,&p[i].c,&p[i].d);
p[i].time=abs(p[i].a-p[i].c)+abs(p[i].b-p[i].d);
time[i]=h*+m;
for(int j=;j<i;j++)
if(time[i]-time[j]>p[j].time+abs(p[i].a-p[j].c)+abs(p[i].b-p[j].d)){
//V[i].push_back(j);
V[j].push_back(i);
}
}
printf("%d\n",n-hungary());
}
return ;
}

poj 2060 Taxi Cab Scheme (二分匹配)的更多相关文章

  1. poj 2060 Taxi Cab Scheme &lpar;最小路径覆盖&rpar;

    http://poj.org/problem?id=2060 Taxi Cab Scheme Time Limit: 1000MS   Memory Limit: 30000K Total Submi ...

  2. poj 2060 Taxi Cab Scheme(DAG图的最小路径覆盖)

    题意: 出租车公司有M个订单. 订单格式:     hh:mm  a  b  c  d 含义:在hh:mm这个时刻客人将从(a,b)这个位置出发,他(她)要去(c,d)这个位置. 规定1:从(a,b) ...

  3. POJ:2060-Taxi Cab Scheme(最小路径覆盖)

    传送门:http://poj.org/problem?id=2060 Taxi Cab Scheme Time Limit: 1000MS Memory Limit: 30000K Total Sub ...

  4. Taxi Cab Scheme POJ &amp&semi;&amp&semi; HDU

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

  5. UVA 1201 - Taxi Cab Scheme(二分图匹配&plus;最小路径覆盖&rpar;

    UVA 1201 - Taxi Cab Scheme 题目链接 题意:给定一些乘客.每一个乘客须要一个出租车,有一个起始时刻,起点,终点,行走路程为曼哈顿距离,每辆出租车必须在乘客一分钟之前到达.问最 ...

  6. 二分图最小路径覆盖--poj2060 Taxi Cab Scheme

    Taxi Cab Scheme 时间限制: 1 Sec  内存限制: 64 MB 题目描述 Running a taxi station is not all that simple. Apart f ...

  7. Taxi Cab Scheme UVALive - 3126 最小路径覆盖解法&lpar;必须是DAG,有向无环图&rpar; &equals; 结点数-最大匹配

    /** 题目:Taxi Cab Scheme UVALive - 3126 最小路径覆盖解法(必须是DAG,有向无环图) = 结点数-最大匹配 链接:https://vjudge.net/proble ...

  8. 【HDU1960】Taxi Cab Scheme(最小路径覆盖)

    Taxi Cab Scheme Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  9. HDU 1350 Taxi Cab Scheme

    Taxi Cab Scheme Time Limit: 10000ms Memory Limit: 32768KB This problem will be judged on HDU. Origin ...

随机推荐

  1. bzoj3489 A simple rmq problem 可持久化树套树

    先预处理出两个个数组pre,next.pre[i]表示上一个与i位置数字相同的位置,若不存在则设为0:next[i]表示下一个与i位置数字相同的位置,若不存在则设为n+1.那么一个满足在区间[L,R] ...

  2. iOS 开发http post 文件的上传

    iOS开发网络篇—文件的上传 说明:文件上传使用的时POST请求,通常把要上传的数据保存在请求体中.本文介绍如何不借助第三方框架实现iOS开发中得文件上传. 由于过程较为复杂,因此本文只贴出部分关键代 ...

  3. 如何在 Docker 容器中运行 Kali Linux 2&period;0

    https://linux.cn/article-6103-1.html Kali Linux 是一个对于安全测试人员和白帽的一个知名操作系统.它带有大量安全相关的程序,这让它很容易用于渗透测试.最近 ...

  4. coding规约的网站&comma; 从sonar中链接过去

    一个coding规约的网站, 从sonar中链接过去的. 挺好. https://wiki.sei.cmu.edu/confluence/display/seccode/SEI+CERT+Coding ...

  5. linux c 开发通用结构,框架

    转自:http://www.maomao365.com/?p=673 了解其它语言的框架例:java Struts1.Struts2.Hibernate.Mybatis.Ibatis.Spring 等 ...

  6. 阿里云&period;log

    申请证书审核失败的原因及处理方法;( 新添加站点 免费版 SSL 网页内不能有 HTTPS的连接:更多点击连接)

  7. 洛谷P1198 &lbrack;JSOI2008&rsqb;最大数(BZOJ&period;1012 )

    To 洛谷.1198 最大数 题目描述 现在请求你维护一个数列,要求提供以下两种操作: 1. 查询操作. 语法:Q L 功能:查询当前数列中末尾L个数中的最大的数,并输出这个数的值. 限制:L不超过当 ...

  8. whatweb工具

    WhatWeb WhatWeb可以用来确定服务器使用的CMS.博客平台.统计分析软件包.JavaScript库等.这个工具有超过900个插件用来扫描目标. 使用方法: root@root:/pente ...

  9. &lbrack;C&num;&sol;Java&rsqb; C&num;中调用Servlet示例

    需求 通用消息接口使用servlet作为服务器端服务接口,第三方应用程序通过http post的方式调用servlet,实现与通用消息接口的调用连接. 参数说明如下: msgTitle:消息标题,描述 ...

  10. Java 中的 I&sol;O

    I/O 指的是 input 和 output ,也就是输入和输出,我们说的是 Java 中的 I/O,那我们就在站在虚拟机的角度去看看有哪些输入和输出.输入又可以称为数据源端,能想到的会有,文件,网络 ...