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

  • 联系
  • 订阅
  • 管理

View Post

poj 3041 Asteroids 最小点覆盖

  构图方式如下:

  以row行号作为x集合顶点, col行号作为y集合顶点,根据题目给出的坐标x,y用边连接X,Y集合的顶点,求最小点覆盖数

#include <iostream>
using namespace std;

const int N = 505;

bool maze[N][N];
bool isvisit[N];
int match[N];
int n, k;

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

int main()
{
	int x, y;
	memset(maze, false, sizeof(maze));

	cin >> n >> k;

	while (k--)
	{
		cin >> x >> y;
		maze[x][y] = true;
	}

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

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

posted on 2011-02-10 12:17  sysuwhj  阅读(257)  评论(0)    收藏  举报

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