POJ 2060(最小路径覆盖 = |G| - 最大匹配数)

#include <iostream>
#include <cstdio>
#include <iomanip>
#include <string>
#include <cstdlib>
#include <cstring>
#include <queue>
#include <set>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <stack>

#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define ll long long
#define ull unsigned long long
#define uint unsigned int

using namespace std;

const int maxn = 666;

struct Node {
	int _time, a, b, c, d;
}a[maxn];

bool isok(Node A, Node B) {
	int cost = abs(A.a - A.c) + abs(A.b - A.d);
	int cost2 = abs(A.c - B.a) + abs(A.d - B.b);
	return A._time + cost + cost2 + 1 <= B._time;
}

int mmap[maxn][maxn], uesd[maxn], macth[maxn];
int n, t;

bool find(int x) {
	for (int i = 1; i <= n; i++) {
		if (mmap[x][i] == 1 && !uesd[i]) {
			uesd[i] = 1;
			if (macth[i] == -1 || find(macth[i])) {
				macth[i] = x;
				return true;
			}
		}
	}
	return false;
}

int main() {
	scanf("%d", &t);
	while (t--) {
		memset(mmap, 0, sizeof(mmap));
		memset(macth, -1, sizeof(macth));
		scanf("%d", &n);
		int hour, mi;
		for (int i = 1; i <= n; i++) {
			scanf("%d:%d%d%d%d%d", &hour, &mi, &a[i].a, &a[i].b, &a[i].c, &a[i].d);
			a[i]._time = hour * 60 + mi;
		}
		for (int i = 1; i <= n; i++) {
			for (int j = i + 1; j <= n; j++) {
				if (isok(a[i], a[j]))
					mmap[i][j] = 1;
			}
		}
		int ans = 0;
		for (int i = 1; i <= n; i++) {
			memset(uesd, 0, sizeof(uesd));
			if (find(i))ans++;
		}
		printf("%d\n", n - ans);
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值