Taxi Cab Scheme

Time Limit: 10000ms
Memory Limit: 32768KB

This problem will be judged on HDU. Original ID: 1350
64-bit integer IO format: %I64d      Java class name: Main

 
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 <bits/stdc++.h>
using namespace std;
const int maxn = ;
struct GUEST {
int s,t,x[],y[];
bool operator<(const GUEST &t) const {
return s < t.s;
}
} guest[maxn];
vector<int>g[maxn];
int Link[maxn];
bool used[maxn];
bool match(int u){
for(int i = g[u].size()-; i >= ; --i){
if(!used[g[u][i]]){
used[g[u][i]] = true;
if(Link[g[u][i]] == - || match(Link[g[u][i]])){
Link[g[u][i]] = u;
return true;
}
}
}
return false;
}
int main() {
int kase,n,h,m;
scanf("%d",&kase);
while(kase--) {
scanf("%d",&n);
for(int i = ; i < n; ++i) {
scanf("%d:%d %d %d %d %d",&h,&m,&guest[i].x[],&guest[i].y[],&guest[i].x[],&guest[i].y[]);
guest[i].s = h* + m;
guest[i].t = guest[i].s + abs(guest[i].x[] - guest[i].x[]) + abs(guest[i].y[] - guest[i].y[]);
}
sort(guest,guest+n);
for(int i = ; i < maxn; ++i) g[i].clear();
for(int i = ; i < n; ++i)
for(int j = i + ; j < n; ++j) {
int d = abs(guest[i].x[] - guest[j].x[]) + abs(guest[i].y[] - guest[j].y[]);
if(guest[i].t + d < guest[j].s) g[i].push_back(j);
}
memset(Link,-,sizeof Link);
int ret = ;
for(int i = ; i < n; ++i){
memset(used,false,sizeof used);
if(match(i)) ++ret;
}
printf("%d\n",n-ret);
}
return ;
}

HDU 1350 Taxi Cab Scheme的更多相关文章

  1. 1350 Taxi Cab Scheme DAG最小路径覆盖

    对于什么是DAG最小路径覆盖以及解题方法在我的另外的博客已经有了.http://www.cnblogs.com/Potato-lover/p/3980470.html 此题的题意: 公交车(出租车)车 ...

  2. Taxi Cab Scheme POJ && HDU

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

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

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

  4. poj 2060 Taxi Cab Scheme (二分匹配)

    Taxi Cab Scheme Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 5710   Accepted: 2393 D ...

  5. poj 2060 Taxi Cab Scheme (最小路径覆盖)

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

  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 最小路径覆盖解法(必须是DAG,有向无环图) = 结点数-最大匹配

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

  8. UVA 1201 - Taxi Cab Scheme(二分图匹配+最小路径覆盖)

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

  9. poj2060——Taxi Cab Scheme(最小路径覆盖)

    Description Running a taxi station is not all that simple. Apart from the obvious demand for a centr ...

随机推荐

  1. .NET 图片解密为BASE64

    #region 图片加密 /// <summary> /// 加密本地文件 /// </summary> /// <param name="inputname& ...

  2. [UVALive 6661 Equal Sum Sets] (dfs 或 dp)

    题意: 求从不超过 N 的正整数其中选取 K 个不同的数字,组成和为 S 的方法数. 1 <= N <= 20  1 <= K<= 10  1 <= S <= 15 ...

  3. linux下的静态库创建与查看,及如何查看某个可执行依赖于哪些动态库

    linux下的静态库创建与查看,及如何查看某个可执行依赖于哪些动态库   创建静态库:ar -rcs test.a *.o查看静态库:ar -tv test.a解压静态库:ar -x test.a 查 ...

  4. Swift 实践之UIWebView

    1.选中工程,点击右键,New File>在iOS下选中Othe>Empty,生成一个.js的脚本文件,将代码粘贴过去保存; var script = document.createEle ...

  5. DB-MySQL:MySQL 处理重复数据

    ylbtech-DB-MySQL:MySQL 处理重复数据 1.返回顶部 1. MySQL 处理重复数据 有些 MySQL 数据表中可能存在重复的记录,有些情况我们允许重复数据的存在,但有时候我们也需 ...

  6. 匹配替换指定文本为html标签

    最近看了一道前端面试题,是关于正则的,用尽可能低复杂度的函数,匹配替换指定文本为html标签,题目是这样的: 特定语法匹配替换 说明:匹配字符串中形如 =g文字文字= 的语法,并将相应部分转化为对应的 ...

  7. IOC-Castle Windsor映射

    Castle最早在2003年诞生于Apache Avalon项目,目的是为了创建一个IOC(控制反转)框架.发展到现在已经有四个组件了,分别是ActiveRecord(ORM组件),Windsor(I ...

  8. javascript中菜单栏切换案例

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  9. 分享一个正则对html标签的替换

    replace_html(parm){ let self = this; return self.trim(parm.replace(new RegExp("<[^<]*> ...

  10. Codeforces Round #282 (Div. 2) A

    解题思路:用数组将每一个显示数字可能表示的数字种数存储起来即可 反思:第一次做的时候没有做出来是因为题意理解错误,第二次WA是因为情况没有考虑完全,1对应有7个数字,5对应有4个数字       A. ...