zoukankan      html  css  js  c++  java
  • HDU——T 1068 Girls and Boys

    http://acm.hdu.edu.cn/showproblem.php?pid=1068

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


    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 
     
     
    (男女没有关系)最大独立子集=总点数-最大匹配数
    因为男女人数不是分开的,所以在同一集合,最大匹配数/=2;
     1 #include <cstring>
     2 #include <cstdio>
     3 
     4 using namespace std;
     5 
     6 const int N(2333);
     7 int n,match[N];
     8 bool map[N][N],vis[N];
     9 
    10 bool find(int u)
    11 {
    12     for(int v=0;v<n;v++)
    13     if(map[u][v]&&!vis[v])
    14     {
    15         vis[v]=1;
    16         if(!match[v]||find(match[v]))
    17         {
    18             match[v]=u;
    19             return true;
    20         }
    21     }
    22     return false;
    23 }
    24 
    25 inline void read(int &x)
    26 {
    27     x=0; register char ch=getchar();
    28     for(;ch>'9'||ch<'0';) ch=getchar();
    29     for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
    30 }
    31 
    32 int AC()
    33 {
    34     for(int ans=0;~scanf("%d",&n);ans=0)
    35     {
    36         for(int v,u,q,i=0;i<n;i++)
    37         {
    38             read(u);
    39             for(read(q);q--;)
    40                 read(v),map[u][v]=1;
    41         }
    42         for(int i=0;i<n;i++)
    43         {
    44             if(find(i)) ans++;
    45             memset(vis,0,sizeof(vis));
    46         }
    47         printf("%d
    ",n-ans/2);
    48         memset(map,0,sizeof(map));
    49         memset(match,0,sizeof(match));
    50     }
    51     return 0;
    52 }
    53 
    54 int I_want_AC=AC();
    55 int main(){;}
    ——每当你想要放弃的时候,就想想是为了什么才一路坚持到现在。
  • 相关阅读:
    六 .Flask 案例
    五 .Flask 蓝图(文件目录结构)
    四 .Flask 模板 中间件 特殊装饰器 CBV 正则 基础知识(使用)
    七 .Django 模板(template)
    三 .Flask 登录案例认证装饰器 session
    二 .Flask 配置文件 路由 视图 请求 响应 cookie session 闪现 基础知识(使用)
    一 .Flask介绍和基本使用
    一 .微信消息推送
    二 .redis在django中使用
    一 python+redis使用(字典 列表)
  • 原文地址:https://www.cnblogs.com/Shy-key/p/7425076.html
Copyright © 2011-2022 走看看