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. Fiddler 无法监测WCF通信疑问

    别人的可以检测到通信,我的为什么不行呢? 使用的是basicHttp协议,应该可以的啊,着的是非常奇怪

  2. 数据库-mongodb-常用命令

    展示当前集合列表 1 show dbs 查看查询命令 1 db.stu.find().explain(); 结果中的 "cursor":"BasicCursor" ...

  3. POJ 1950

    直接DFS,因为实在没想到什么剪枝了... 注意一点是,10.11使用的是1011哦 #include <iostream> #include <cstdio> #includ ...

  4. HDU 3507

    斜率DP入门题.推荐看看这篇http://www.cnblogs.com/ka200812/archive/2012/08/03/2621345.html 看过之后,自己思考,发现有些不妥之处就是,其 ...

  5. Unable to access the IIS metabase

    https://stackoverflow.com/questions/12859891/error-unable-to-access-the-iis-metabase 解决方法1 On Window ...

  6. 英语发音规则---B字母

    英语发音规则---B字母 一.总结 一句话总结: 1.B发[b]音? bike [baɪk] n. 自行车 bus [bʌs] n. 公共汽车 bag [bæg] n. 袋:猎获物 baby ['be ...

  7. nginx报错日志:see security.limit_extensions

    访问出现部分.js.css等部分文件被拒绝错误日志如下: 19:20:13 [error] 1181#0: *287 FastCGI sent in stderr: "Access to t ...

  8. 多线程与MySQL(十)

    1.1 多线程 在传统操作系统中,每个进程有一个地址空间,而且默认就有一个控制线程 线程顾名思义,就是一条流水线工作的过程,一条流水线必须属于一个车间,一个车间的工作过程是一个进程 车间负责把资源整合 ...

  9. javascript中document.getElementsByClassName兼容性封装方法一

    var getElmsByClsName = function(className, results) { results = results || []; // 判断浏览器是否支持 getEleme ...

  10. PopupWindow实现点击外部不消失

    View contentView = LayoutInflater.from(MainActivity.this).inflate(R.layout.alert_ip, null); final Po ...