• hdu 1068 Girls and Boys (最大独立集)


    Girls and Boys
    Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 13556    Accepted Submission(s): 6385

    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

    C/C++:

     1 #include <map>
     2 #include <queue>
     3 #include <cmath>
     4 #include <vector>
     5 #include <string>
     6 #include <cstdio>
     7 #include <cstring>
     8 #include <climits>
     9 #include <iostream>
    10 #include <algorithm>
    11 #define INF 0xffffff
    12 using namespace std;
    13 const int my_max = 1005;
    14 
    15 int n, m, a, b, my_G[my_max][my_max], my_book[my_max], my_right[my_max];
    16 
    17 bool my_dfs(int x)
    18 {
    19     for (int i = 0; i < n; ++ i)
    20     {
    21         if (my_G[x][i] && !my_book[i])
    22         {
    23             my_book[i] = 1;
    24             if (!my_right[i] || my_dfs(my_right[i]))
    25             {
    26                 my_right[i] = x;
    27                 return true;
    28             }
    29         }
    30     }
    31     return false;
    32 }
    33 
    34 int my_hungarian()
    35 {
    36     int my_cnt = 0;
    37     for (int i = 0; i < n; ++ i)
    38     {
    39         memset (my_book, 0, sizeof(my_book));
    40         if (my_dfs(i))
    41             ++ my_cnt;
    42     }
    43     return my_cnt / 2;
    44 }
    45 
    46 int main()
    47 {
    48     while (~scanf("%d", &n))
    49     {
    50         memset(my_right, 0, sizeof(my_right));
    51         memset(my_G, 0, sizeof(my_G));
    52         for (int i = 0; i < n; ++ i)
    53         {
    54             scanf("%d: (%d)", &a, &m);
    55             while (m --)
    56             {
    57                 scanf("%d", &b);
    58                 my_G[a][b] = 1;
    59             }
    60         }
    61 
    62         printf("%d
    ", n - my_hungarian());
    63     }
    64     return 0;
    65 }
  • 相关阅读:
    Silverlight+WCF 实战网络象棋最终篇之房间装修WCF端(二)
    win7下如何添加虚拟网卡(转)
    Python天天美味(12) 条件判断的缩写(转)
    MENUITEMINFO结构的翻译(转)
    C语言写Python extension实践(转)
    Python天天美味(15) Python正则表达式操作指南(re使用)(转)
    Python Import机制备忘模块搜索路径(sys.path)、嵌套Import、package Import(转)
    python单例模式(转)
    Python 操作剪贴板(转)
    Base64加密原理(转)
  • 原文地址:https://www.cnblogs.com/GetcharZp/p/9462268.html
Copyright © 2020-2023  润新知