LA 3126 - Taxi Cab Scheme【DAG最小路径覆盖】
来源:互联网 发布:西安中国银行软件中心 编辑:程序博客网 时间:2024/06/06 05:28
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1127
DAG最小路径覆盖 = 点数 - 最大匹配数。
代码:
#include <stdio.h>#include <ctime>#include <math.h>#include <limits.h>#include <complex>#include <string>#include <functional>#include <iterator>#include <algorithm>#include <vector>#include <stack>#include <queue>#include <set>#include <map>#include <list>#include <bitset>#include <sstream>#include <iomanip>#include <fstream>#include <iostream>#include <ctime>#include <cmath>#include <cstring>#include <cstdio>#include <time.h>#include <ctype.h>#include <string.h>#include <assert.h>using namespace std;int n;int p[510][510];int book[510];int match[510];bool vis[510];bool dfs(int u){ for (int i = 1; i <= n; i++) { if (book[i] == 0 && p[u][i] == 1) { book[i] = 1; if (match[i] == 0 || dfs(match[i])) { match[i] = u; return true; } } } return false;}struct node{ int x1, y1, x2, y2; int st, ed;}taxi[510];int get_dis(node a, node b){ return abs(a.x2 - b.x1) + abs(a.y2 - b.y1);}int main(){ int t; scanf("%d", &t); while (t--) { memset(p, 0, sizeof(p)); memset(match, 0, sizeof(match)); memset(vis, false, sizeof(vis)); scanf("%d", &n); int a, b, c, d, e, f; char s[10]; for (int i = 1;i <= n;i++) { scanf("%s %d %d %d %d", s, &c, &d, &e, &f); a = (s[0] - '0') * 10 + (s[1] - '0'); b = (s[3] - '0') * 10 + (s[4] - '0'); // printf(" %d %d %d %d %d %d\n", a, b, c, d, e, f); taxi[i].st = a * 60 + b; taxi[i].ed = taxi[i].st + abs(c - e) + abs(d - f); taxi[i].x1 = c; taxi[i].y1 = d; taxi[i].x2 = e; taxi[i].y2 = f; } for (int i = 1;i <= n;i++) for (int j = 1;j <= n;j++) { if (taxi[i].ed + get_dis(taxi[i],taxi[j]) < taxi[j].st) p[i][j] = 1; } int ans = 0; for (int i = 1; i <= n; i++) { memset(book, 0, sizeof(book)); if (dfs(i)) ans++; } printf("%d\n", n - ans); } return 0;}
0 0
- LA 3126 - Taxi Cab Scheme【DAG最小路径覆盖】
- POJ 2060 Taxi Cab Scheme DAG最小路径覆盖
- UVAlive3126 Taxi Cab Scheme(DAG的最小路径覆盖)
- UVALive3126[Taxi Cab Scheme] DAG最小路径覆盖模型
- UVALive 3126 Taxi Cab Scheme(DAG的最小路径覆盖)
- PKU2060 Taxi Cab Scheme - 最小路径覆盖
- POJ2060 Taxi Cab Scheme [最小路径覆盖]
- hdu1350 Taxi Cab Scheme (最小路径覆盖)
- poj2060 Taxi Cab Scheme 最小路径覆盖
- HDU1350 Taxi Cab Scheme (最小路径覆盖)
- LA 3126 - Taxi Cab Scheme DAG上的二分匹配
- POJ--2060[Taxi Cab Scheme] 最小路径覆盖
- POJ2060 Taxi Cab Scheme(最小路径覆盖)
- POJ 2060 Taxi Cab Scheme (最小路径覆盖)
- hdu_1960/1350 Taxi Cab Scheme 最小路径覆盖
- POJ-2060 Taxi Cab Scheme 最小路径覆盖(匈牙利)
- POJ 2060 Taxi Cab Scheme(匈牙利—最小路径覆盖)
- Poj-2060 Taxi Cab Scheme 二分图最小路径覆盖
- leetcode6 ZigZag Conversion
- 奇怪的连接错误 LNK1181: 无法打开输入文件“,5.01”
- HDU 5427
- 字符串左移
- 分享一个仿Eclipse配色的Android Studio主题配置文件
- LA 3126 - Taxi Cab Scheme【DAG最小路径覆盖】
- ios-自定义画板
- SGU101 Domino(欧拉回路)
- 牛客面试常考算法题精讲部分题目c/c++代码
- 常量接口设计模式
- openstack部署(1)-准备工作
- 1039. 到底买不买(20)
- Font.Style(Delphi)
- SQLite数据库存储、Android四大组件