【POJ 3041】Asteroids (最小点覆盖)

每次选择清除一行或者一列上的小行星。最少选择几次。

将行和列抽象成点,第i行为节点i+n,第j列为节点j,每个行星则是一条边,连接了所在的行列。

于是问题转化成最小点覆盖。二分图的最小点覆盖==最大匹配。

#include <cstdio>
#include <cstring>
const int N=505<<1;
int n,vis[N],link[N],g[N][N];
int find(int u)
{
	for(int i=1; i<=n*2; i++)
		if(g[u][i]&&!vis[i])
		{
			vis[i]=1;
			if(!link[i]||find(link[i]))
			{
				link[i]=u;
				return 1;
			}
		}
	return 0;
}
int solve(){
	memset(link,0,sizeof link);
	int ans=0;
	for(int i=1;i<=n;i++){
		memset(vis,0,sizeof vis);
		if(find(i))ans++;
	}
	return ans;
}
int main(){
	int m,u,v;
	scanf("%d%d",&n,&m);
	memset(g,0,sizeof g);
	while(m--){
		scanf("%d%d",&u,&v);
		g[u+n][v]=g[v][u+n]=1;
	}
	printf("%d\n",solve());
}

  

时间: 2024-10-09 23:35:01

【POJ 3041】Asteroids (最小点覆盖)的相关文章

poj 3041 Asteroids(最小点覆盖)

http://poj.org/problem?id=3041 Asteroids Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 17543   Accepted: 9548 Description Bessie wants to navigate her spaceship through a dangerous asteroid field in the shape of an N x N grid (1 <= N <

Asteroids POJ - 3041 二分图最小点覆盖

Asteroids POJ - 3041 Bessie wants to navigate her spaceship through a dangerous asteroid field in the shape of an N x N grid (1 <= N <= 500). The grid contains K asteroids (1 <= K <= 10,000), which are conveniently located at the lattice point

Asteroids POJ - 3041 【最小点覆盖集】

Bessie wants to navigate her spaceship through a dangerous asteroid field in the shape of an N x N grid (1 <= N <= 500). The grid contains K asteroids (1 <= K <= 10,000), which are conveniently located at the lattice points of the grid. Fortun

POJ 3041(最小点覆盖)

题意: 假如你现在正处在一个N*N的矩阵中,这个矩阵里面有K个障碍物,你拥有一把武器,一发弹药一次能消灭一行或一列的障碍物,求最小的弹药消灭全部障碍物 输入为:     N K 接下来有K行,每行包含障碍物的坐标,即r行c列; 如: 3 4 1 1 1 3 2 2 3 2 输出为:     花费最小的弹药数 思路:将i行作为X集合,将j列作为Y集合,这样原来的问题-用最少的炮弹打掉全部障碍物,转化为了这么一个问题: 在二分图中选择尽量少的点,使得每条边至少有一个端点被选中 裸的最小点覆盖问题,运

POJ 3041.Asteroids 最小顶点覆盖

Asteroids Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22905   Accepted: 12421 Description Bessie wants to navigate her spaceship through a dangerous asteroid field in the shape of an N x N grid (1 <= N <= 500). The grid contains K a

POJ 3041 Asteroids (图论-最小点覆盖)

Asteroids Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 15079   Accepted: 8240 Description Bessie wants to navigate her spaceship through a dangerous asteroid field in the shape of an N x N grid (1 <= N <= 500). The grid contains K as

poj 3041——Asteroids

poj       3041——Asteroids Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22604   Accepted: 12247 Description Bessie wants to navigate her spaceship through a dangerous asteroid field in the shape of an N x N grid (1 <= N <= 500). The g

二分图匹配(匈牙利算法) POJ 3041 Asteroids

题目传送门 1 /* 2 题意:每次能消灭一行或一列的障碍物,要求最少的次数. 3 匈牙利算法:把行和列看做两个集合,当有障碍物连接时连一条边,问题转换为最小点覆盖数==二分图最大匹配数 4 趣味入门:http://blog.csdn.net/dark_scope/article/details/8880547 5 */ 6 #include <cstdio> 7 #include <algorithm> 8 #include <cstring> 9 #include

POJ 3041 Asteroids (匈牙利算法)

Asteroids Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 14388 Accepted: 7828 Description Bessie wants to navigate her spaceship through a dangerous asteroid field in the shape of an N x N grid (1 <= N <= 500). The grid contains K astero

poj3041 Asteroids --- 最小点覆盖

#include<cstdio> #include<cstring> #include<cmath> #include<iostream> #include<algorithm> #include<vector> #include<queue> const int maxn=510; using namespace std; int my[maxn],mx[maxn],vis[maxn],e[maxn][maxn],n;