Poj-2060 Taxi Cab Scheme 二分图最小路径覆盖

题目链接

出租车公司有n个预约, 每个预约有时间和地点, 地点分布在二维整数坐标系上, 地点之间的行驶时间为两点间的曼哈顿距离(|x1 - x2| + |y1 - y2|)。一辆车可以在运完一个乘客后运另一个乘客, 条件是此车要在预约开始前一分钟之前到达出发地, 问最少需要几辆车搞定所有预约。





#include <stdio.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
const int maxn = 505;
const int Mod = 1000000007;
const double inf = 1<<30;
int n;
int map[maxn][maxn];
struct node
{
	int sta,t;
	int sx,sy,ex,ey;
}book[maxn];
int cx[maxn],cy[maxn];
bool vis[maxn];
bool FindPath( int u )
{
	for( int i = u+1; i <= n; i ++ )
	{
		if( !vis[i] && map[u][i] )
		{
			vis[i] = true;
			if( cy[i] == -1 || FindPath( cy[i] ) )
			{
				cy[i] = u;
				cx[u] = i;
				return true;
			}
		}
	}
	return false;
}
int MaxMatch()
{
	int ans = 0;
	memset( cx,-1,sizeof(cx) );
	memset( cy,-1,sizeof(cy) );
	for( int i = 1; i <= n; i++ )
	{
		if( cx[i] == -1 )
		{
			memset( vis,0,sizeof(vis) );
			ans += FindPath( i );
		}
	}
	return ans;
}
int main()
{
	#ifndef ONLINE_JUDGE   
	freopen("data.txt","r",stdin);   
	#endif
	int cas,h,m;
	scanf("%d",&cas);
	while( cas -- )
	{
		scanf("%d",&n);
		memset( map,0,sizeof(map) );
		for( int i = 1; i <= n; i ++ )
		{
			scanf("%d:%d%d%d%d%d",&h,&m,&book[i].sx,&book[i].sy,&book[i].ex,&book[i].ey);
			book[i].sta = h*60 + m;
			book[i].t = abs( book[i].sx - book[i].ex ) + abs( book[i].sy - book[i].ey );
		}
		for( int i = 1; i <= n; i ++ )
		{
			for( int j = i+1; j <= n; j ++ )
			{
				int dis = abs( book[j].sx - book[i].ex ) + abs( book[j].sy - book[i].ey );
				if( book[i].t + dis + 1 <= book[j].sta - book[i].sta )
					map[i][j] = 1;
			}
		}
		printf("%d\n",n - MaxMatch());
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值