码迷,mamicode.com
首页 > 其他好文 > 详细

poj3041 Asteroids --- 最小点覆盖

时间:2014-07-21 23:29:42      阅读:199      评论:0      收藏:0      [点我收藏+]

标签:os   io   for   re   c   amp   



#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;

int path(int i)
{
    int j;
    for(j=1;j<=n;j++)
    {
        if(e[i][j]&&!vis[j])
        {
            vis[j]=1;
            if(my[j]==-1||path(my[j]))
            {
                my[j]=i;
                mx[i]=j;
                return 1;
            }
        }
    }
    return 0;
}

int hungry()
{
    int i,res=0;
    memset(mx,-1,sizeof mx);
    memset(my,-1,sizeof my);
    for(i=1;i<=n;i++)
    {
        if(mx[i]==-1)
        {
            memset(vis,0,sizeof vis);
            res+=path(i);
        }
    }
    return res;
}

int main()
{
    int a,b,k;
    while(~scanf("%d%d",&n,&k))
    {
        memset(e,0,sizeof e);
        while(k--)
        {
            scanf("%d%d",&a,&b);
            e[a][b]=1;
        }
        printf("%d\n",hungry());
    }
    return 0;
}


poj3041 Asteroids --- 最小点覆盖,布布扣,bubuko.com

poj3041 Asteroids --- 最小点覆盖

标签:os   io   for   re   c   amp   

原文地址:http://blog.csdn.net/u011032846/article/details/38024039

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!