poj2060——Taxi Cab Scheme(最小路径覆盖)
Posted qldabiaoge
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了poj2060——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
题意是说有n个出车安排,一辆车能接到这个安排的条件是:1、这辆车第一次发车;2、这辆车接了上一个安排,回到这个安排的起点的时间正好是这个安排的前一分钟或者更早
每一次安排有五个输入数据,第一个是发车时间,2、3是起点位置,4、5是终点位置,因此计算每两个安排之间的时间差可以用第一个的最后两个数和第二个的第二和三个数。我一开始就是这里没明白才不知道怎么算两个安排之间的关系
接下来就是用二分图,把每个安排都放在二分图的两个点集上,显然两个相同的任务之间不会有边,只有符合题意的两个不同的任务可以连一条边
以上内容来自 https://blog.csdn.net/blue_skyrim/article/details/51331383
跑一边匈牙利就直接出来了 这个的数据量小 暴力也可以出来
1 #include <cstdio> 2 #include <cstring> 3 #include <queue> 4 #include <cmath> 5 #include <algorithm> 6 #include <set> 7 #include <iostream> 8 #include <map> 9 #include <stack> 10 #include <string> 11 #include <vector> 12 #define pi acos(-1.0) 13 #define eps 1e-6 14 #define fi first 15 #define se second 16 #define lson l,m,rt<<1 17 #define rson m+1,r,rt<<1|1 18 #define bug printf("******") 19 #define mem(a,b) memset(a,b,sizeof(a)) 20 #define fuck(x) cout<<"["<<x<<"]"<<endl 21 #define f(a) a*a 22 #define sf(n) scanf("%d", &n) 23 #define sff(a,b) scanf("%d %d", &a, &b) 24 #define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c) 25 #define pf printf 26 #define FRE(i,a,b) for(i = a; i <= b; i++) 27 #define FREE(i,a,b) for(i = a; i >= b; i--) 28 #define FRL(i,a,b) for(i = a; i < b; i++) 29 #define FRLL(i,a,b) for(i = a; i > b; i--) 30 #define FIN freopen("in.txt","r",stdin) 31 #define lowbit(x) x&-x 32 #pragma comment (linker,"/STACK:102400000,102400000") 33 using namespace std; 34 const int maxn = 200004; 35 typedef long long LL; 36 int cas, n, vis[505], mp[505][505], match[505], dfscnt; 37 struct node { 38 int time, a, b, c, d, later; 39 } qu[maxn]; 40 int cal(int x1, int y1, int x2, int y2) { 41 return abs(x1 - x2) + abs(y1 - y2); 42 } 43 int dfs(int rt) { 44 for (int i = 1 ; i <= n ; i++) { 45 if (mp[rt][i]) { 46 if (vis[i] != dfscnt) { 47 vis[i] = dfscnt; 48 if (!match[i] || dfs(match[i])) { 49 match[i] = rt; 50 return 1; 51 } 52 } 53 } 54 } 55 return 0; 56 } 57 58 int main() { 59 scanf("%d", &cas); 60 while(cas--) { 61 scanf("%d", &n); 62 mem(vis, 0); 63 mem(mp, 0); 64 mem(match, 0); 65 dfscnt = 0; 66 for (int i = 1 ; i <= n ; i++) { 67 int x, y; 68 scanf("%d:%d %d%d%d%d", &x, &y, &qu[i].a, &qu[i].b, &qu[i].c, &qu[i].d); 69 qu[i].time = x * 60 + y; 70 qu[i].later = qu[i].time + cal(qu[i].a, qu[i].b, qu[i].c, qu[i].d); 71 } 72 for (int i = 1 ; i <= n ; i++) 73 for (int j = i ; j <= n; j++) 74 if (qu[i].later + cal(qu[i].c, qu[i].d, qu[j].a, qu[j].b) < qu[j].time) mp[i][j] = 1; 75 int ans = 0; 76 for (int i = 1 ; i <= n ; i++) { 77 dfscnt++; 78 if (dfs(i)) ans++; 79 } 80 printf("%d ", n - ans); 81 } 82 return 0; 83 }
以上是关于poj2060——Taxi Cab Scheme(最小路径覆盖)的主要内容,如果未能解决你的问题,请参考以下文章
二分图最小路径覆盖--poj2060 Taxi Cab Scheme
UVALive3126 Taxi Cab Scheme —— 最小路径覆盖
UVaLive 3126 Taxi Cab Scheme (最小路径覆盖)