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



08:00 10 11 9 16 
08:07 9 16 10 11 

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

跑一边匈牙利就直接出来了  这个的数据量小  暴力也可以出来

 #include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <algorithm>
#include <set>
#include <iostream>
#include <map>
#include <stack>
#include <string>
#include <vector>
#define pi acos(-1.0)
#define eps 1e-6
#define fi first
#define se second
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define bug printf("******")
#define mem(a,b) memset(a,b,sizeof(a))
#define fuck(x) cout<<"["<<x<<"]"<<endl
#define f(a) a*a
#define sf(n) scanf("%d", &n)
#define sff(a,b) scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define pf printf
#define FRE(i,a,b) for(i = a; i <= b; i++)
#define FREE(i,a,b) for(i = a; i >= b; i--)
#define FRL(i,a,b) for(i = a; i < b; i++)
#define FRLL(i,a,b) for(i = a; i > b; i--)
#define FIN freopen("in.txt","r",stdin)
#define lowbit(x) x&-x
#pragma comment (linker,"/STACK:102400000,102400000")
using namespace std;
const int maxn = ;
typedef long long LL;
int cas, n, vis[], mp[][], match[], dfscnt;
struct node {
int time, a, b, c, d, later;
} qu[maxn];
int cal(int x1, int y1, int x2, int y2) {
return abs(x1 - x2) + abs(y1 - y2);
}
int dfs(int rt) {
for (int i = ; i <= n ; i++) {
if (mp[rt][i]) {
if (vis[i] != dfscnt) {
vis[i] = dfscnt;
if (!match[i] || dfs(match[i])) {
match[i] = rt;
return ;
}
}
}
}
return ;
} int main() {
scanf("%d", &cas);
while(cas--) {
scanf("%d", &n);
mem(vis, );
mem(mp, );
mem(match, );
dfscnt = ;
for (int i = ; i <= n ; i++) {
int x, y;
scanf("%d:%d %d%d%d%d", &x, &y, &qu[i].a, &qu[i].b, &qu[i].c, &qu[i].d);
qu[i].time = x * + y;
qu[i].later = qu[i].time + cal(qu[i].a, qu[i].b, qu[i].c, qu[i].d);
}
for (int i = ; i <= n ; i++)
for (int j = i ; j <= n; j++)
if (qu[i].later + cal(qu[i].c, qu[i].d, qu[j].a, qu[j].b) < qu[j].time) mp[i][j] = ;
int ans = ;
for (int i = ; i <= n ; i++) {
dfscnt++;
if (dfs(i)) ans++;
}
printf("%d\n", n - ans);
}
return ;
}

最新文章

  1. 04.LoT.UI 前后台通用框架分解系列之——轻巧的弹出框
  2. 理解DOM事件流的三个阶段
  3. jeasyUI的treegrid批量删除多行(转载)
  4. 元素JS拖动的实现
  5. 微信稳居Android App排行榜4月份国内榜首
  6. 【UVA 1411】 Ants (KM)
  7. 使用javascript获取网址的各个参数
  8. Web的鼠标拖动效果
  9. mysql 初始化
  10. Hibernate学习之hibernate状态
  11. Ubuntu 12.10 安装JDK7
  12. android-support-v7-appcompat
  13. QT编程环境搭建
  14. linux视频之media媒体框架
  15. js页面(页面上无服务端控件,且页面不刷新)实现请求一般处理程序下载文件方法
  16. Bootstrap3 排版-改变大小写
  17. jpa Auditor 自动赋值与自定义 @CreatedBy @LastModifiedBy @CreatedDate @LastModifiedDate
  18. jdk7 并行计算框架Fork/Join
  19. SpringSecurityOAuth使用JWT Token
  20. jmeter插件使用说明

热门文章

  1. lintcode: Missing String
  2. loadrunner_遇到cookie接口_3种应对方法
  3. 反片语 (Ananagrams,UVa 156)
  4. Bootstrap框架(图标)
  5. vmware安装64位系统“此主机支持 Intel VT-x,但 Intel VT-x 处于禁用状态”的问题
  6. css贝塞尔曲线模仿饿了么购物车小球动画
  7. JavaScript闭包总结
  8. StrBlob类——智能指针作为成员
  9. 《学习OpenCV》课后习题解答4
  10. PokeCats开发者日志(十)