• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

  • 联系
  • 订阅
  • 管理

View Post

poj 2536 Gopher II 最大二分匹配

       这题难点建图。

       建图方式如下:要是在给定的s时间内能跑到洞穴(判断两点距离),那么那两个点是连通的,否则就不连通

 

#include<iostream>
using namespace std;

const int MAX = 300;

struct coordinate
{
	double x,y;
};

coordinate gopher[MAX];
coordinate holes[MAX];

bool arcs[MAX][MAX];
bool isvisit[MAX];
int match[MAX];
int n, m, s, v;

bool find(int u)
{
	for (int i = 1; i <= m; i++)
		if (arcs[u][i] && !isvisit[i])
		{
			isvisit[i] = true;
			if (!match[i] || find(match[i]))
			{
				match[i] = u;
				return true;
			}
		}

	return false;
}

int main()
{
	while (cin >> n >> m >> s >> v)
	{
		double d = s*v*s*v;
		for (int i = 0; i < n; i++)
			cin >> gopher[i].x >> gopher[i].y;

		for (int i = 0; i < m; i++)
			cin >> holes[i].x >> holes[i].y;

		memset(arcs, false, sizeof(arcs));
		memset(match, 0, sizeof(match));
		for (int i = 0; i < n; i++)
			for (int j = 0; j < m; j++)
				if ((holes[j].x - gopher[i].x)*(holes[j].x - gopher[i].x) + (holes[j].y - gopher[i].y)*(holes[j].y - gopher[i].y) <= d)
					arcs[i+1][j+1] = true;

		int ans = 0;
		for (int i = 1; i <= n; i++)
		{
			memset(isvisit, false, sizeof(isvisit));
			if (find(i))
				ans++;
		}

		cout << n - ans << endl;
	}
	return 0;
}

posted on 2011-01-29 22:23  sysuwhj  阅读(388)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3