zoukankan      html  css  js  c++  java
  • hdu 1068 最大独立集=节点数最大匹配

    Girls and Boys

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


    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

    求一个集合,使这个集合中任意两两都没有关系,及最大独立集=节点数-最大匹配
    代码:
    View Code
     1 #include <iostream>
     2 #include <stdio.h>
     3 #include <string.h>
     4 using namespace std;
     5 
     6 bool map[2000][2000];
     7 int pre[2000];
     8 int flag[2000];
     9 int n;
    10 
    11 int find(int cur)
    12 {
    13     int i;
    14     for(i=0;i<n;i++)
    15     {
    16         if(map[cur][i] && !flag[i])
    17         {
    18             flag[i]=true;
    19             if(pre[i]==-1 || find(pre[i]))
    20             {
    21                 pre[i]=cur;
    22                 return 1;
    23             }
    24         }
    25     }
    26     return 0;
    27 }
    28 
    29 
    30 int main()
    31 {
    32     while(scanf("%d",&n)!=EOF)
    33     {
    34         int sum=0;
    35         memset(map,false,sizeof(map));
    36         memset(pre,-1,sizeof(pre));
    37         int p,q,k,i,j;
    38         for(i=0;i<n;i++)
    39         {
    40             scanf("%d: (%d) ",&p,&q);
    41             for(j=0;j<q;j++)
    42             {
    43                 scanf("%d",&k);
    44                 map[p][k]=true;
    45             }
    46         }
    47         for(i=0;i<n;i++)
    48         {
    49             memset(flag,0,sizeof(flag));
    50             sum+=find(i);
    51         }
    52         printf("%d\n",n-sum/2);
    53     }
    54     return 0;
    55 }
  • 相关阅读:
    easyui Combobox用法
    Jquery EasyUI treegrid的使用(asp.net后台)
    异步加载Echars +ASP.Net后台(柱状图)
    jQuery Validate表单验证帐号是否存在
    EasyUI Datebox 日期验证 开始日期小于结束时间
    gdb调试常用命令
    简答哈希实现 (nyoj 138 找球号2)
    03_汇编语言(n个数找最大值)
    02_汇编语言(子程序设计01_基本输入输出函数模板)
    01_汇编语言(基本格式_模板)
  • 原文地址:https://www.cnblogs.com/shenshuyang/p/2628500.html
Copyright © 2011-2022 走看看