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): 8223    Accepted Submission(s): 3768


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
题目分析:
把所有点拆成两个点,然后根据题意建边,做二分图匹配,然后要求的是最大独立点集,也就是所有能够匹配上的都把能匹配的点减去一个,那么只和它相连的点就孤立了,而和其他点相连的点,会在去掉后来的匹配的过程中也变成孤立的点
 
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cctype>
#include <iostream>
#define MAX 5000

using namespace std;

int n,m;

struct Edge
{
    int v,next;
}e[MAX*50];

int head[MAX];
int cc;

void add ( int u , int v )
{
    e[cc].v = v;
    e[cc].next = head[u];
    head[u] = cc++;
}

void scan ( int &x )
{
    char ch;
    x = 0;
    while ( !isdigit(ch) ) ch = getchar();
    while ( isdigit(ch) )
    {
        x = x*10+ch-48;
        ch = getchar();
    }
}

char s[50];

int linker[MAX];
int used[MAX];

bool dfs ( int u )
{
    for ( int i = head[u]; ~i ; i = e[i].next )
    {
        int v = e[i].v;
        if ( used[v] ) continue;
        used[v] = true;
        if ( linker[v] == -1 || dfs ( linker[v] ) )
        {
            linker[v] = u;
            return true;
        }
    }
    return false;
}

int hungary ( )
{
    int res = 0;
    memset ( linker , -1 , sizeof ( linker ) );
    for ( int u = 0 ; u < n ; u++ )
    {
        memset ( used , 0 , sizeof ( used ) );
        if ( dfs(u) ) res++;
    }
    return res/2;   
}

int main ( )
{
    int  v;
   // freopen ( "a.txt" , "r" , stdin );
    while ( ~scanf ( "%d" , &n ) )
    {
        memset ( head , -1 , sizeof ( head ) );
        cc = 0;
        for ( int i = 0 ; i < n ; i++ )
        {
            scanf ( "%s" , s );
            scan ( m );
            for ( int j = 0 ; j < m ; j++ )
            {
                scanf ( "%d" , &v );
                add ( i , v+n );
            }  
        }
        printf ( "%d\n" ,  n-hungary() );
    }
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
【2018年MIT新书】 Artificial Unintelligence: How Computers Misunderstand the World (Meredith Broussard, MIT Press) 人工非智能-计算机是如何误导世界的? A guide to understanding the inner workings and outer limits of technology and why we should never assume that computers always get it right. In Artificial Unintelligence, Meredith Broussard argues that our collective enthusiasm for applying computer technology to every aspect of life has resulted in a tremendous amount of poorly designed systems. We are so eager to do everything digitally—hiring, driving, paying bills, even choosing romantic partners—that we have stopped demanding that our technology actually work. Broussard, a software developer and journalist, reminds us that there are fundamental limits to what we can (and should) do with technology. With this book, she offers a guide to understanding the inner workings and outer limits of technology—and issues a warning that we should never assume that computers always get things right. Making a case against technochauvinism—the belief that technology is always the solution—Broussard argues that it's just not true that social problems would inevitably retreat before a digitally enabled Utopia. To prove her point, she undertakes a series of adventures in computer programming. She goes for an alarming ride in a driverless car, concluding “the cyborg future is not coming any time soon”; uses artificial intelligence to investigate why students can't pass standardized tests; deploys machine learning to predict which passengers survived the Titanic disaster; and attempts to repair the U.S. campaign finance system by building AI software. If we understand the limits of what we can do with technology, Broussard tells us, we can make better choices about what we should do with it to make the world better for everyone.
提供的源码资源涵盖了Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 适合毕业设计、课程设计作业。这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。 所有源码均经过严格测试,可以直接运行,可以放心下载使用。有任何使用问题欢迎随时与博主沟通,第一时间进行解答!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值