UVA 1201 - Taxi Cab Scheme

题目链接

题意:给定一些乘客。每一个乘客须要一个出租车,有一个起始时刻,起点,终点,行走路程为曼哈顿距离,每辆出租车必须在乘客一分钟之前到达。问最少须要几辆出租车

思路:假设一辆车载完一个乘客a,能去载乘客b,就连一条有向边,这样做完整个图形成一个DAG,然后要求的最少数量就是最小路径覆盖。利用二分图最大匹配去做,把每一个点拆成两点。假设有边就连边,做一次最大匹配。n - 最大匹配数就是答案

代码:

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <vector>
using namespace std; const int N = 505; int t, n; struct People {
int s, x1, y1, x2, y2;
void read() {
int h, m;
scanf("%d:%d%d%d%d%d", &h, &m, &x1, &y1, &x2, &y2);
s = h * 60 + m;
}
bool operator < (const People& c) const {
return s < c.s;
}
} p[N]; vector<int> g[N]; bool judge(People a, People b) {
int tmp = a.s + abs(a.x2 - a.x1) + abs(a.y2 - a.y1) + abs(a.x2 - b.x1) + abs(a.y2 - b.y1);
if (tmp < b.s) return true;
return false;
} int match[N], vis[N]; bool dfs(int u) {
for (int i = 0; i < g[u].size(); i++) {
int v = g[u][i];
if (vis[v]) continue;
vis[v] = 1;
if (match[v] == -1 || dfs(match[v])) {
match[v] = u;
return true;
}
}
return false;
} int hungary() {
int ans = 0;
memset(match, -1, sizeof(match));
for (int i = 0; i < n; i++) {
memset(vis, 0, sizeof(vis));
if (dfs(i)) ans++;
}
return ans;
} int main() {
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
g[i].clear();
p[i].read();
}
sort(p, p + n);
for (int i = 0; i < n; i++)
for (int j = i + 1; j < n; j++) {
if (judge(p[i], p[j]))
g[i].push_back(j);
}
printf("%d\n", n - hungary());
}
return 0;
}

UVA 1201 - Taxi Cab Scheme(二分图匹配+最小路径覆盖)的更多相关文章

  1. Taxi Cab Scheme UVALive - 3126 最小路径覆盖解法(必须是DAG,有向无环图) = 结点数-最大匹配

    /** 题目:Taxi Cab Scheme UVALive - 3126 最小路径覆盖解法(必须是DAG,有向无环图) = 结点数-最大匹配 链接:https://vjudge.net/proble ...

  2. POJ 1422 Air Raid(二分图匹配最小路径覆盖)

    POJ 1422 Air Raid 题目链接 题意:给定一个有向图,在这个图上的某些点上放伞兵,能够使伞兵能够走到图上全部的点.且每一个点仅仅被一个伞兵走一次.问至少放多少伞兵 思路:二分图的最小路径 ...

  3. POJ3020 二分图匹配——最小路径覆盖

    Description The Global Aerial Research Centre has been allotted the task of building the fifth gener ...

  4. POJ 3020 Antenna Placement【二分匹配——最小路径覆盖】

    链接: http://poj.org/problem?id=3020 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#probl ...

  5. POJ:3020-Antenna Placement(二分图的最小路径覆盖)

    原题传送:http://poj.org/problem?id=3020 Antenna Placement Time Limit: 1000MS Memory Limit: 65536K Descri ...

  6. POJ 3020:Antenna Placement(无向二分图的最小路径覆盖)

    Antenna Placement Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6334   Accepted: 3125 ...

  7. hdu3861 强连通分量缩点+二分图最最小路径覆盖

    The King’s Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  8. poj 2060 Taxi Cab Scheme (二分匹配)

    Taxi Cab Scheme Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 5710   Accepted: 2393 D ...

  9. (匹配 最小路径覆盖)Air Raid --hdu --1151

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=1151 http://acm.hust.edu.cn/vjudge/contest/view.action ...

随机推荐

  1. A - Team

    Problem description One day three best friends Petya, Vasya and Tonya decided to form a team and tak ...

  2. 2.Dubbo开源分布式服务框架(JAVA RPC)

    1. Dubbo介绍 Dubbox是阿里巴巴公司开源的一个高性能优秀的服务框架,使得应用可通过高性能RPC(即远程调用)实现服务的输出和输入功能, 可以和Spring框架无集成.Dubbo是一款高性能 ...

  3. Obsolete---标记方法 类过期

    最近做一个接口的修改,由于是很老的接口,不太了解外部有多少地方引用了它. 但是内部的方法由于业务发展已经不太适合现在的需求,想改又不该动.所以想到了如果设置为过期. Obsolete 属性将某个程序实 ...

  4. 【sqli-labs】 less9 GET - Blind - Time based. - Single Quotes (基于时间的GET单引号盲注)

    加and http://localhost/sqli/Less-9/?id=1' and '1'='1%23 http://localhost/sqli/Less-9/?id=1' and '1'=' ...

  5. webapi部署到IIS 404错误

    环境:win2008r2+IIS 解决方案: 添加一个映射 可执行文件地址(根据系统决定64位可32位): C:\Windows\Microsoft.NET\Framework64\v4.0.3031 ...

  6. JavaScript中原生事件

    DOM0事件模型: 所有浏览器都支持,只能注册一种事件 1.绑定: document.getElementById("id").onclick = function(e){}; 解 ...

  7. wget 批量下载网站目录下的文件

    执行如下命令就会自动下载 http://www.iyunwei.com/docs/ 下面的所有文件: wget -nd -r -l1 --no-parent http://www.iyunwei.co ...

  8. 【转载】java读取.properties配置文件的几种方法

    读取.properties配置文件在实际的开发中使用的很多,总结了一下,有以下几种方法(仅仅是我知道的):一.通过jdk提供的java.util.Properties类.此类继承自java.util. ...

  9. PAT_A1145#Hashing - Average Search Time

    Source: PAT A1145 Hashing - Average Search Time (25 分) Description: The task of this problem is simp ...

  10. Python对JSON的操作 day3

    下面将为大家介绍如何使用python语言来编码和解码json对象: json串就是一个字符串,json串必须用双引号,不能使用单引号 使用json函数需要导入json库,import json 1.j ...