• poj 1466 Girls and Boys (最大独立集)


    http://poj.org/problem?id=1466

    题意:一些 boys 和girls  有暧昧关系,我们要选出 一些人,这些人 任意两个人之间没有暧昧 关系,求最多可以选出 多少人。

    题解:

     最大独立集,这里建的是双向图,所以,最大匹配要除以 2;

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<cmath>
     4 #include<iostream>
     5 #include<algorithm>
     6 #include<set>
     7 #include<map>
     8 #include<queue>
     9 #include<vector>
    10 #include<string>
    11 #define Min(a,b) a<b?a:b
    12 #define Max(a,b) a>b?a:b
    13 #define CL(a,num) memset(a,num,sizeof(a));
    14 #define eps  1e-6
    15 #define inf 10001000
    16 
    17 #define ll   __int64
    18 
    19 #define  read()  freopen("data.txt","r",stdin) ;
    20 const double pi  = acos(-1.0);
    21 const int maxn = 510;
    22 
    23 using namespace std;
    24 int n;
    25 int mat[maxn][maxn],result[maxn],vis[maxn] ;
    26 
    27 int find(int a)
    28 {
    29     int i ;
    30     for(i = 0 ; i < n;i++)
    31     {
    32         if(mat[a][i]&&!vis[i])
    33         {
    34             vis[i] = 1;
    35             if(result[i] == 0||find(result[i]))
    36             {
    37                 result[i] = a ;
    38                 return 1 ;
    39 
    40             }
    41         }
    42     }
    43     return 0 ;
    44 }
    45 
    46 int main()
    47 {
    48     //read();
    49     int cas = 0,i ,a,num,b;
    50     while(scanf("%d",&n)!=EOF)
    51     {
    52        CL(result,0);
    53        CL(mat,0) ;
    54        for(i = 0 ; i < n;i++)
    55        {
    56            scanf("%d: (%d)",&a,&num);
    57            while(num--)
    58            {
    59                scanf("%d",&b);
    60                mat[a][b] = 1;
    61            }
    62        }
    63        int ans = 0 ;
    64        for(i =0 ;i < n;i++)
    65        {
    66            CL(vis,0);
    67            if(find(i))ans++;
    68        }
    69 
    70        printf("%d\n",n - ans/2);
    71     }
    72 }
  • 相关阅读:
    Ubuntu 12.10使用apt安装Oracle/Sun JDK
    织梦(dedecms)系统常用全局变量调用标签及路径
    Lighttpd虚拟主机和多域名的配置
    Ubuntu解压命令大全
    OFBiz终于起航了
    eclipse 安装gradle 插件的三种方式
    验证码
    session的使用
    实验二
    作业2(魔术)
  • 原文地址:https://www.cnblogs.com/acSzz/p/2714213.html
Copyright © 2020-2023  润新知