POJ 2060 Taxi Cab Scheme【最小路径覆盖】

T - Taxi Cab Scheme

Time Limit:1000MS     Memory Limit:30000KB     64bit IO Format:%I64d & %I64u

Submit Status Practice POJ 2060

Appoint description: 
System Crawler  (2014-08-22)

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

今天我又把题目粘过来了, 原因很简单,  我又读错题了  TAT

大意:有n个点,给你一个起始时间,从一个点到另一个点需要的时间是横纵坐标差的绝对值之和, 问需要派出多少cab分析:最小路径覆盖 = n - 最大匹配

代码:

 1 #include <iostream>
 2 #include <cstring>
 3 #include <cstdio>
 4 #include <vector>
 5 #include <cmath>
 6 using namespace std;
 7
 8 const int maxn = 505;
 9 const int INF = 1000000000;
10
11 int n;
12 int vis[maxn];
13 int Link[maxn];
14 vector<int> G[maxn];
15 bool Find(int u) {
16     for(int i = 0; i < G[u].size(); i++) {
17         int v = G[u][i];
18         if(!vis[v]) {
19             vis[v] = 1;
20             if(Link[v] == - 1 || Find(Link[v])) {
21                 Link[v] = u;
22                 return true;
23             }
24         }
25     }
26     return false;
27 }
28
29 int solve() {
30     int cnt = 0;
31     memset(Link, -1, sizeof(Link));
32     for(int i = 1; i <= n; i++) {
33         if(G[i].size()) {
34             memset(vis, 0, sizeof(vis));
35             if(Find(i)) cnt++;
36         }
37     }
38     return cnt;
39 }
40
41 int a[maxn], b[maxn], c[maxn], d[maxn], t[maxn];
42 bool check(int i, int j) {
43     if(t[j] - ((fabs(c[i] - a[i]) + fabs(d[i] - b[i]) + t[i]) + fabs(a[j] - c[i]) + fabs(b[j] - d[i])) >= 1) {
44         return true;
45     }
46     return false;
47 }
48
49 int main() {
50     int tt;
51     int x, y;
52     scanf("%d",&tt);
53     while(tt--) {
54         scanf("%d",&n);
55         for(int i = 1; i <= n; i++) {
56             G[i].clear();
57             scanf("%d:%d",&x,&y);
58             t[i] = x * 60 + y;
59             scanf("%d %d %d %d",&a[i], &b[i], &c[i], &d[i]);
60         }
61         for(int i = 1; i <= n; i++) {
62             for(int j = 1; j <= n; j++) {
63                 if(i == j) continue;
64                 if(check(i, j)) {
65                     G[i].push_back(j);
66                 }
67             }
68         }
69         printf("%d\n", n - solve());
70     }
71     return 0;
72 }

时间: 2024-10-09 06:02:01

POJ 2060 Taxi Cab Scheme【最小路径覆盖】的相关文章

poj 2060 Taxi Cab Scheme 最小路径覆盖

//二分匹配的最小路径覆盖 //对于第i次ride,如果在第i次ride结束后还能在第j次ride出发前赶到第j次的出发点 //那么i到j就有一条边 //根据最小路径覆盖 = N - 最大匹配即可得到答案 #include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> using namespace std; const int maxn  = 510; int line[max

UVALive3126 Taxi Cab Scheme —— 最小路径覆盖

题目链接:https://vjudge.net/problem/UVALive-3126 题解: 代码如下: 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cstdlib> 5 #include <string> 6 #include <vector> 7 #include <map> 8 #include <se

hdu1350Taxi Cab Scheme (最小路径覆盖)

Taxi Cab Scheme Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 712 Accepted Submission(s): 337 Problem Description Running a taxi station is not all that simple. Apart from the obvious demand f

poj 2060 Taxi Cab Scheme (二分匹配)

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

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

题意: 出租车公司有M个订单. 订单格式:     hh:mm  a  b  c  d 含义:在hh:mm这个时刻客人将从(a,b)这个位置出发,他(她)要去(c,d)这个位置. 规定1:从(a,b)到(c,d)所花的时间为:abs(a-c)+abs(b-d). 规定2:一辆出租车如果要接单,必须在客人出发前1分钟(包括)以前接单. 问,最少派出多少辆出租车,可以完成所有任务. 思路: 把每一笔单看成一个点,如果完成第i个单后可以接到第j个单,则 i->j连上线. 则题为:求这个DAG图的最小路

POJ - 2060 Taxi Cab Scheme 二分图 最小路径覆盖

题目大意:有n项任务,给出每项任务的出发时间,出发地点和目的地. 当一个任务完成之后,如果 当前时间 + 到达另一个任务的出发地的时间 <= 另一个任务的出发时间 - 1 的话,那么就可以让这个人接下去完成这个任务了 问至少需要派多少人才可以完成任务 解题思路:这题和 poj-3216 Repairing Company很像 两个点集都是任务,如果一个任务完成了可以接下来完成另一个任务的话,那么这两个任务之间就存在关系了,这样二分图就建成了 因为要把所有的任务都完成,也就是说要覆盖所有点,这就变

POJ 2594 Treasure Exploration(最小路径覆盖变形)

POJ 2594 Treasure Exploration 题目链接 题意:有向无环图,求最少多少条路径能够覆盖整个图,点能够反复走 思路:和普通的最小路径覆盖不同的是,点能够反复走,那么事实上仅仅要在多一步.利用floyd求出传递闭包.然后依据这个新的图去做最小路径覆盖就可以 代码: #include <cstdio> #include <cstring> #include <vector> #include <algorithm> using names

poj 1422 Air Raid (最小路径覆盖)

链接:poj 1422 题意:有n个点和m条有向边,现在要在点上放一些伞兵,伞兵可以沿着图走, 直到不能走为止,每条边有且仅有一个伞兵走过,问最少放多少个伞兵 思路:求的最小路径覆盖,用二分图来做 对于这样的一个有向图做最小路径覆盖,首先建图 然后每一条有向边对应左边的点指向右边的点 这样建好图之后求最大匹配数 最小路径覆盖=点数-最大匹配数 [cpp] view plaincopyprint? #include<stdio.h> #include<string.h> int n,

POJ 2594 —— Treasure Exploration——————【最小路径覆盖、可重点、floyd传递闭包】

Treasure Exploration Time Limit:6000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice POJ 2594 Description Have you ever read any book about treasure exploration? Have you ever see any film about treasure exploratio