POJ 2536 Gopher II(二分图最大匹配,裸题)

62 篇文章 0 订阅

二分图匹配,裸题

本题要点:
1、二分图匹配:
左部点是n个老鼠,右部点是m个鼠洞。当老鼠i和洞j之间的距离超过 s*v 的时候,i和j之间不存在边。
用增光路算法算出最大匹配数 ans。 ans表示可以生存的老鼠, n - ans 表示被吃掉的老鼠。
2、多 case

#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
using namespace std;
const int MaxN = 110;
int match[MaxN];
double gopher_x[MaxN], gopher_y[MaxN], hole_x[MaxN], hole_y[MaxN];
int n, m;
int	s, v;
double step;
bool vis[MaxN];

bool dfs(int x)
{
	for(int y = 1; y <= m; ++y)
	{
		double x1, y1;
		x1 = gopher_x[x] - hole_x[y], y1 = gopher_y[x] - hole_y[y];
		if(!vis[y] && sqrt(x1 * x1 + y1 * y1) <= (double)(s * v))
		{
			vis[y] = true;
			if(match[y] == 0 || dfs(match[y]))
			{
				match[y] = x;
				return true;
			}
		}
	}
	return false;
}

int main()
{
	while(scanf("%d%d%d%d", &n, &m, &s, &v) != EOF)
	{
		step = (double)(s * v);
		memset(match, 0, sizeof match);
		for(int i = 1; i <= n; ++i)
		{
			scanf("%lf%lf", &gopher_x[i], &gopher_y[i]);
		}
		for(int i = 1; i <= m; ++i)
		{
			scanf("%lf%lf", &hole_x[i], &hole_y[i]);
		}
		int ans = 0;
		for(int i = 1; i <= n; ++i)
		{
			memset(vis, 0, sizeof vis);
			if(dfs(i))
				++ans;
		}
		printf("%d\n", n - ans);
	}
	return 0;
}

/*
2 2 5 10
1.0 1.0
2.0 2.0
100.0 100.0
20.0 20.0
*/

/*
1
*/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值