Taxi Cab Scheme POJ - 2060 二分图最小路径覆盖
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.
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
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
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
OJ-ID:
poj-2060
author:
Caution_X
date of submission:
20191002
tags:
二分图最小点覆盖
description modelling:
给定一个二维坐标图,从一个点a到另一个点b费时(a.x-b.x)+(a.y-b.y),现在有n个出租车订单,每个订单提供起点终点坐标和用车时间,问最少需要几辆出租车才可以在用车时间内接完所有客人
major steps to solve it:
(1) 假设我们派出了n辆出租车,如果两个订单恰好可以由一辆车完成,那么出租车数-1.
(2) 建图:现在以一辆车能否在接完这单并且及时接下下一单为依据建立一个二分图,如果两个订单可以由一辆车接下,那么这两个订单设定成匹配状态
(3) 算出最小路径覆盖(二分图最小路径覆盖:用最少的边覆盖所有的点)
最小路径覆盖=N-二分图最大匹配
AC code:
#include<cstdio>
#include<cstring>
#include<math.h>
using namespace std;
int N;
int line[][];
int g[],used[];
struct Node{
int t,h,m,a,b,c,d;
}node[];
int is_link(Node A,Node B)
{
int dis1=fabs(A.a-A.c)+fabs(A.b-A.d);
int dis2=fabs(B.a-A.c)+fabs(B.b-A.d);
return dis1+dis2+<=fabs(A.t-B.t)?:;
}
bool found(int x)
{
for(int i=;i<=N;i++) {
if(line[x][i]&&!used[i]) {
used[i]=;
if(g[i]==-||found(g[i])) {
g[i]=x;
return true;
}
}
}
return false;
}
int main()
{
//freopen("input.txt","r",stdin);
int T;
scanf("%d",&T);
while(T--) {
scanf("%d",&N);
memset(line,,sizeof(line));
memset(g,-,sizeof(g));
for(int i=;i<=N;i++) {
int h,m,a,b,c,d;
scanf("%d:%d %d %d %d %d",&node[i].h,&node[i].m,&node[i].a,&node[i].b,&node[i].c,&node[i].d);
node[i].t=node[i].h*+node[i].m;
}
for(int i=;i<=N;i++) {
for(int j=i+;j<=N;j++) {
line[i][j]=is_link(node[i],node[j]);
}
}
int ans=N;
for(int i=;i<=N;i++) {
memset(used,,sizeof(used));
if(found(i)) ans--;
}
printf("%d\n",ans);
}
return ;
}
Taxi Cab Scheme POJ - 2060 二分图最小路径覆盖的更多相关文章
- UVAlive3126 Taxi Cab Scheme(DAG的最小路径覆盖)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=32568 [思路] DAG的最小路径覆盖. 将每个人看做一个结点,如 ...
- UVALive-3126 Taxi Cab Scheme (DAG的最小路径覆盖)
题目大意:要给n个人安排车,已知每个人的出发时间和起点与终点,问最少需要安排几辆车才能完成任务. 题目分析:最小路径覆盖.如果送完a到目的地后能在b出发之前赶来接b,那么连一条有向边a->b,最 ...
- POJ 3020 (二分图+最小路径覆盖)
题目链接:http://poj.org/problem?id=3020 题目大意:读入一张地图.其中地图中圈圈代表可以布置卫星的空地.*号代表要覆盖的建筑物.一个卫星的覆盖范围是其周围上下左右四个点. ...
- [bzoj2150]部落战争_二分图最小路径覆盖
部落战争 bzoj-2150 题目大意:题目链接. 注释:略. 想法: 显然是最小路径覆盖,我们知道:二分图最小路径覆盖等于节点总数-最大匹配. 所以我们用匈牙利或者dinic跑出最大匹配,然后用总结 ...
- 二分图最小路径覆盖--poj2060 Taxi Cab Scheme
Taxi Cab Scheme 时间限制: 1 Sec 内存限制: 64 MB 题目描述 Running a taxi station is not all that simple. Apart f ...
- Taxi Cab Scheme POJ && HDU
Online Judge Problem Set Authors Online Contests User Web Board Home Page F.A.Qs Statistical Charts ...
- POJ 3020 Antenna Placement (二分图最小路径覆盖)
<题目链接> 题目大意:一个矩形中,有N个城市’*’,现在这n个城市都要覆盖无线,每放置一个基站,至多可以覆盖相邻的两个城市.问至少放置多少个基站才能使得所有的城市都覆盖无线? 解题分析: ...
- 【HDU3861 强连通分量缩点+二分图最小路径覆盖】
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3861 题目大意:一个有向图,让你按规则划分区域,要求划分的区域数最少. 规则如下:1.有边u到v以及有 ...
- hdu 1151 Air Raid(二分图最小路径覆盖)
http://acm.hdu.edu.cn/showproblem.php?pid=1151 Air Raid Time Limit: 1000MS Memory Limit: 10000K To ...
随机推荐
- windows 10使用vscode进行远程代码开发 | tutorial to use vscode for remote development using ssh on windows
本文首发于个人博客https://kezunlin.me/post/c93b6ba6/,欢迎阅读最新内容! tutorial to use vscode for remote development ...
- hibernate中的merge()方法
Hibernate提供有save().persist().savaOrUpdate()和merge()等方法来提供插入数据的功能.前三者理解起来较后者容易一些,而merge()方法从api中的介绍就可 ...
- Python中model转dict
问题 在query出来的行信息object中有一个dict变量,这个变量存储了字典信息 for u in session.query(User).all(): print u.__dict__ 但是这 ...
- [反汇编] 获取上一个栈帧的ebp
使用代码 lea ecx, [ebp+4+参数长度] 就可以实现. 如下图,理解栈帧的结构,很好理解. 虽然也是 push param的,但这部分在恢复时被调用函数会恢复的,因此这并不算esp的值. ...
- python基础(32):进程(二)
1. multiprocess模块 仔细说来,multiprocess不是一个模块而是python中一个操作.管理进程的包. 之所以叫multi是取自multiple的多功能的意思,在这个包中几乎包含 ...
- Java生鲜电商平台-深入订单拆单架构与实战
Java生鲜电商平台-深入订单拆单架构与实战 Java生鲜电商中在做拆单的需求,细思极恐,思考越深入,就会发现里面涉及的东西越来越多,要想做好订单拆单的功能,还是相当有难度, 因此总结了一下拆单功能细 ...
- QT信号槽连接语法总结
信号槽是 Qt 框架引以为豪的机制之一. 所谓信号槽,实际就是观察者模式.当某个事件发生之后,比如,按钮检测到自己被点击了一下,它就会发出一个信号(signal).这种触发是没有目的的,类似广播.如果 ...
- qt 使用OpenCV
使用MinGW编译OpenCV源码 下载OpenCV源码.CMake编译工具 编译安装完: Qt工程配置 INCLUDEPATH += D:/qt_work/opencv/build/install/ ...
- Android Studio compile error ---- enum constant INSTANT_RUN_REPLACEMENT does not
原文:http://stackoverflow.com/questions/34868876/android-studio-compile-error-enum-constant-instant-ru ...
- Autofac 应用于IIS托管的WEB程序,注册程序集被回收的问题
现项目开始全面接入Autofac,但上线了后发现,iis进程被回收后,在访问网页提示找不到注册在Autofac中的类型,或者实例.现在处理办法记录如下: 1. IIS托管的应用程序,在首次加载时,所有 ...