poj 3041Asteroids 二分匹配求最小点覆盖模板题
来源:互联网 发布:下载配色软件 编辑:程序博客网 时间:2024/05/16 01:38
//最大匹配=最小覆盖
//这题是求最小覆盖点的模板题
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int maxn = 510;
int line[maxn][maxn];
int match[maxn];
int vis[maxn];
int N , K;
int find(int start)
{
for(int i = 1;i <= N;i++)
{
if(line[start][i] && !vis[i])
{
vis[i] = 1;
if(match[i] == -1 || find(match[i]))
{
match[i] = start;
return 1;
}
}
}
return 0;
}
void Match()
{
memset(match, -1 ,sizeof(match));
int ans = 0;
for(int i = 1 ; i <=N ;i++)
{
memset(vis , 0 ,sizeof(vis));
if(find(i))
ans++;
}
printf("%d\n", ans);
}
int main()
{
//freopen("in.txt", "r",stdin);
while(scanf("%d%d" ,&N ,&K)!=EOF)
{
int r,c;
memset(line, 0 ,sizeof(line));
for(int i = 1;i <= K;i++)
{
scanf("%d%d",&r , &c);
line[r][c] = 1;
}
Match();
}
return 0;
}
//这题是求最小覆盖点的模板题
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int maxn = 510;
int line[maxn][maxn];
int match[maxn];
int vis[maxn];
int N , K;
int find(int start)
{
for(int i = 1;i <= N;i++)
{
if(line[start][i] && !vis[i])
{
vis[i] = 1;
if(match[i] == -1 || find(match[i]))
{
match[i] = start;
return 1;
}
}
}
return 0;
}
void Match()
{
memset(match, -1 ,sizeof(match));
int ans = 0;
for(int i = 1 ; i <=N ;i++)
{
memset(vis , 0 ,sizeof(vis));
if(find(i))
ans++;
}
printf("%d\n", ans);
}
int main()
{
//freopen("in.txt", "r",stdin);
while(scanf("%d%d" ,&N ,&K)!=EOF)
{
int r,c;
memset(line, 0 ,sizeof(line));
for(int i = 1;i <= K;i++)
{
scanf("%d%d",&r , &c);
line[r][c] = 1;
}
Match();
}
return 0;
}
0 0
- poj 3041Asteroids 二分匹配求最小点覆盖模板题
- POJ 3041-Asteroids(二分匹配_最小点覆盖)
- POJ 3041 Asteroids 二分匹配 最小点覆盖
- POJ 3041 Asteroids(二分图最大匹配-最小点覆盖)
- poj 3041 Asteroids(二分匹配,最小点覆盖)
- POJ 3401 Asteroids 二分图最大匹配 最小点覆盖
- POJ 3041 Asteroids ( 最小点覆盖数=最大匹配数, 二分图匹配)
- pku 3041 Asteroids(最小点覆盖,最大二分匹配)
- poj 3041 Asteroids 二分图的最大匹配==最小覆盖点。
- poj 3041 Asteroids 最小覆盖点==最大二分匹配
- POJ 3041 Asteroids 最小点覆盖==最大二分匹配
- poj 3041 Asteroids (二分图最大匹配 == 最小点覆盖数)
- poj 3041 Asteroids 最小顶点覆盖 && 二分匹配
- poj 3041 Asteroids -二分匹配-最小顶点覆盖
- poj-3041-Asteroids【二分匹配&&最小顶点覆盖】
- poj 3041 Asteroids 二分图最小点覆盖
- POJ 3041 Asteroids 二分图 最小点覆盖
- POJ - 3041 Asteroids 二分图 最小点覆盖
- 开发环境(摘自网络)
- shell 初步
- 获取当前的viewcontroller
- git如何忽略文件或者文件夹
- Python写的贪吃蛇游戏例子
- poj 3041Asteroids 二分匹配求最小点覆盖模板题
- Combination Sum
- 我的新书——《UGUI全面实践教程》
- Spring绑定参数
- C++ 函数指针与指针函数
- 环境搭建及开发流程(官网翻译Get Started)
- [HiHoCoder]#1015 : KMP算法
- 【Hibernate】Hibernate的在Eclipse+Mysql的配置、安装,纯Java,利用Annotation与HQL完成数据库的增删改查
- undefined reference to XXX