杭电 hdu 1350 和 1960 Taxi Cab Scheme (二分匹配 + 最小路径覆盖)
来源:互联网 发布:通联数据南京分公司 编辑:程序博客网 时间:2024/05/03 04:10
杭电 hdu 1350 和 1960 Taxi Cab Scheme (二分匹配 + 最小路径覆盖)
Taxi Cab Scheme
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 891 Accepted Submission(s): 427
Problem 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.
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
2208:00 10 11 9 1608:07 9 16 10 11208:00 10 11 9 1608:06 9 16 10 11
Sample Output
12
Source
Northwestern Europe 2004
Recommend
JGShining | We have carefully selected several similar problems for you: 1054 1179 1528 1287 1498
题意:这里是一个出租车公司,他们会接很多订单,面对订单,他们考虑派多少车去完成,他们的要求是尽量少的派车出去,要是有派出去的车能过完成第n单订单的时候,
还能及时的感到第n+1单订单的地点,就让他接着完成。否则让其他车尝试,或者派新车。
首先是输入T,表示有多少案例
接着是n,表示有多少单的订单
接着是一个00:00这样模式的时间,表示这个订单要这个时间到达目的地
后面是a,b,c,d,分别表示两个地点a,b,表示出发地,c,d表示目的地
然后告诉你路程的时间计算是 |a - c| + |b - d|单位是分钟
问出租车公司最少要派多少辆车才能准时完成所有订单
题解:这是一道还是能看出来的二分匹配的最小路径覆盖,构造边的时候,将能接下去完成的订单之间连接起来,接着就是基础代码
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <math.h>#include <algorithm>#include <iostream>using namespace std;const int maxn = 505;int n, m;bool map[maxn][maxn]; //记录哪些订单是可以连接下去,也就是时间允许bool vis[maxn];int pri[maxn]; //pri[i] = x,用来判断最后i被x选中,-1则表示没有被选中struct node //记录每一单订单的消息{ int time; int a, b, c, d;}cab[maxn];bool find (int x){ int i; for (i = 1; i <= n; i++) { if (map[x][i] && !vis[i]) //查询可以连续完成的订单,并且是从上到下的遍历 { vis[i] = true; if (pri[i] == -1 || find(pri[i])) //查看是否之前就被选走,要是被选走了,就查看选走的是否有另外的选项 { pri[i] = x; return true; } } } return false;}int main (){ int T, i, j, a, b; scanf ("%d", &T); while (T--) { scanf ("%d", &n); memset (map, 0, sizeof (map)); memset (pri, -1, sizeof (pri)); for (i = 1; i <= n; ++i) { scanf ("%d:%d %d%d%d%d", &a, &b, &cab[i].a, &cab[i].b, &cab[i].c, &cab[i].d); //记录每个订单的信息 cab[i].time = a * 60 + b; } for (i = 1; i < n; ++i) { for (j = i + 1; j <= n; ++j) { if (cab[j].time > (cab[i].time + abs(cab[i].a - cab[i].c) + abs(cab[i].b - cab[i].d) + abs(cab[i].c - cab[j].a) + abs(cab[i].d - cab[j].b))) map[i][j] = 1; //遍历,选择可以连续完成到订单之间进行连线 } } int ant = 0; for (i = 1; i <= n; ++i) { memset (vis, false, sizeof (vis)); if (find(i)) ant++; } printf ("%d\n", n - ant); } return 0;}
0 0
- 杭电 hdu 1350 和 1960 Taxi Cab Scheme (二分匹配 + 最小路径覆盖)
- HDU OJ 1350 Taxi Cab Scheme 【二分图匹配之最小路径覆盖】
- HDU 1350 & HDU 1960 & POJ 2060 Taxi Cab Scheme【二分图之最小路径覆盖,经典】
- hdu 1350 Taxi Cab Scheme(二分图最小路径覆盖)
- HDU 1960 Taxi Cab Scheme(最小路径覆盖)
- Hdu 1350 Taxi Cab Scheme【最小路径覆盖】
- HDU-1350 Taxi Cab Scheme(最小路径覆盖)
- hdu 1960 Taxi Cab Scheme (最小覆盖)
- hdu 1350Taxi Cab Scheme (最小覆盖)
- Poj-2060 Taxi Cab Scheme 二分图最小路径覆盖
- POJ2060 Taxi Cab Scheme【二分图最小路径覆盖】
- POJ - 2060 Taxi Cab Scheme 二分图 最小路径覆盖
- UVA 1201 - Taxi Cab Scheme(二分图匹配+最小路径覆盖)
- hdu 1350 Taxi Cab Scheme(二分匹配)
- PKU2060 Taxi Cab Scheme - 最小路径覆盖
- POJ2060 Taxi Cab Scheme [最小路径覆盖]
- hdu1350 Taxi Cab Scheme (最小路径覆盖)
- poj2060 Taxi Cab Scheme 最小路径覆盖
- iOS C语言7_结构体
- 1044 拦截导弹
- 动画特效四:精致登陆
- HOG特征及在opencv中的提取
- SICP-Exercise 1.9
- 杭电 hdu 1350 和 1960 Taxi Cab Scheme (二分匹配 + 最小路径覆盖)
- 将cxDateEdit控件下拉选择中的按钮文字变中文
- 类的扩展(二):类目、延展、协议和代理
- 南阳理工题目28大数阶乘
- Python文件读取切割
- Windows App开发之编辑文本与绘制图形
- 天声人語 20150718
- Version Control System
- C++项目实践-银行储蓄系统