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 }
  • 相关阅读:
    不定义JQuery插件,不要说会JQuery
    .net深入体验与实战精要--ASP.NET开发大杂烩(转)
    iis7/7.5设置上传文件最大大小
    javascript禁止复制网页内容,兼容三大浏览器
    如何将控制台程序包装成windows服务
    Js获取当前日期时间及其它操作
    JS控制图片拖动 放大 缩小 旋转 支持滚轮放大缩小 IE有效
    js实用功能
    zen-Coding的使用
    使用 MyEclipse远程调试 Java 应用程序
  • 原文地址:https://www.cnblogs.com/shenshuyang/p/2628500.html
Copyright © 2011-2022 走看看