zoukankan      html  css  js  c++  java
  • 杭电1068--Girls and Boys(二分图最大独立集)

    Girls and Boys

    Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 8863    Accepted Submission(s): 4077


    Problem Description
    the second year of the university somebody started a study on the romantic relations between the students. The relation “romantically involved” is defined between one girl and one boy. For the study reasons it is necessary to find out the maximum set satisfying the condition: there are no two students in the set who have been “romantically involved”. The result of the program is the number of students in such a set.

    The input contains several data sets in text format. Each data set represents one set of subjects of the study, with the following description:

    the number of students
    the description of each student, in the following format
    student_identifier:(number_of_romantic_relations) student_identifier1 student_identifier2 student_identifier3 ...
    or
    student_identifier:(0)

    The student_identifier is an integer number between 0 and n-1, for n subjects.
    For each given data set, the program should write to standard output a line containing the result.
     

     

    Sample Input
    7
    0: (3) 4 5 6
    1: (2) 4 6
    2: (0)
    3: (0)
    4: (2) 0 1
    5: (1) 0
    6: (2) 0 1
    3
    0: (2) 1 2
    1: (1) 0
    2: (1) 0
     

     

    Sample Output
    5
    2
     

     

    Source
     

     

    Recommend
    JGShining   |   We have carefully selected several similar problems for you:  1150 1151 1281 1507 1528 
    二分图最大独立集 = 顶点数 - 最大匹配数。 
    本题从整个点集搜索 、并没有将点集分开,相当于搜索了两遍。 所以最大匹配数要除以二。
     1 #include <cstdio>
     2 #include <cstring>
     3 #include <iostream>
     4 using namespace std;
     5 int map[1010][1010], dis[1010], vis[1010];
     6 int n;
     7 bool Dfs(int a)
     8 {
     9     for(int i = 0; i < n; i++)
    10     {
    11         if(map[a][i] && !vis[i])
    12         {
    13             vis[i] = 1;
    14             if(!dis[i] || Dfs(dis[i]))
    15             {
    16                 dis[i] = a;
    17                 return true;
    18             }
    19         }
    20     }
    21     return false;
    22 }
    23 int main()
    24 {
    25     int q, m, GG; 
    26     while(~scanf("%d", &n)) 
    27     {
    28         memset(map, 0, sizeof(map));
    29         memset(dis, 0, sizeof(dis));
    30         for(int i = 0; i < n; i++)
    31         {
    32             scanf("%d: (%d)", &q, &m);
    33             for(int i = 1; i <= m; i++)
    34             {
    35                 scanf("%d", &GG);
    36                 map[q][GG] = 1;
    37             }
    38         }
    39         int sum = 0;
    40         for(int i = 0; i < n; i++)
    41         {
    42             memset(vis, 0, sizeof(vis));
    43             if(Dfs(i))
    44                 sum++;
    45         }
    46         printf("%d
    ", n - sum/2);
    47     }
    48     return 0;
    49 }
     1 #include <cstdio>
     2 #include <cstring>
     3 #include <iostream>
     4 using namespace std;
     5 int map[1010][1010], dis[1010], vis[1010];
     6 int n;
     7 bool Dfs(int a)
     8 {
     9     for(int i = 0; i < n; i++)
    10     {
    11         if(map[a][i] && !vis[i])
    12         {
    13             vis[i] = 1;
    14             if(!dis[i] || Dfs(dis[i]))
    15             {
    16                 dis[i] = a;
    17                 return true;
    18             }
    19         }
    20     }
    21     return false;
    22 }
    23 int main()
    24 {
    25     int q, m, GG; 
    26     while(~scanf("%d", &n)) 
    27     {
    28         memset(map, 0, sizeof(map));
    29         memset(dis, 0, sizeof(dis));
    30         for(int i = 0; i < n; i++)
    31         {
    32             scanf("%d: (%d)", &q, &m);
    33             for(int i = 1; i <= m; i++)
    34             {
    35                 scanf("%d", &GG);
    36                 map[q][GG] = 1;
    37             }
    38         }
    39         int sum = 0;
    40         for(int i = 0; i < n; i++)
    41         {
    42             memset(vis, 0, sizeof(vis));
    43             if(Dfs(i))
    44                 sum++;
    45         }
    46         printf("%d
    ", n - sum/2);
    47     }
    48     return 0;
    49 }
      
  • 相关阅读:
    Repeater控件分页例子
    利用Repeater控件显示主-从关系数据表 (NestedRepeater.aspx)
    Visual C#设计多功能关机程序(2)
    ASP.Net 数据绑定之选择合适的数据控件
    模板化数据绑定控件示例
    Visual C#设计多功能关机程序(1)
    利用Repeater控件显示主-从关系数据表 (NestedRepeater.aspx.cs)
    iBatis 调用 PostgreSQL 存储过程返回结果集
    SubVersion 安装为 Windows 服务 (Service)
    Eclipse 运行使用指定的 JVM m2eclipse 插件找不到 com.sun 的 defaulttools.jar 的解决方案
  • 原文地址:https://www.cnblogs.com/soTired/p/4746260.html
Copyright © 2011-2022 走看看