题目链接:

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

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
解题思路:
处理数据,使用匈牙利算法即可。
AC代码:
#include<stdio.h>
#include<string.h>
const int N=;
int n,e[N][N],match[*N],bk[N];
int maxmatch();
int path(int u); int main()
{
int i,t,x,m;
while(scanf("%d",&n) != EOF)
{
memset(e,,sizeof(e));
for(i=;i<n;i++)
{
scanf("%d: (%d)",&x,&t);
while(t--)
{
scanf("%d",&m);
e[x][m]=;
}
} printf("%d\n",n-maxmatch());//最大点独立集数=顶点数-最大匹配数
}
return ;
}
int maxmatch()
{
int i;
int ans=;
memset(match,-,sizeof(match));
for(i=;i<n;i++)
{
if(match[i]==-)
{
memset(bk,,sizeof(bk));
ans += path(i);
}
}
return ans;
}
int path(int u)
{
int i;
for(i=;i<n;i++)
{
if(e[u][i] && !bk[i])
{
bk[i]=;
if(match[i]==- || path(match[i]))//或而不是且
{
match[i]=u;
match[u]=i;
return ;
}
}
}
return ;
}
//易错分析
//参见注释处
 

HDU 1068 Girls and Boys(模板——二分图最大匹配)的更多相关文章

  1. HDU 1068 Girls and Boys(最大独立集合 = 顶点数 - 最大匹配数)

    HDU 1068 :题目链接 题意:一些男孩和女孩,给出一些人物关系,然后问能找到最多有多少个人都互不认识. 转换一下:就是大家都不认识的人,即最大独立集合 #include <iostream ...

  2. HDU 1068 Girls and Boys 二分图最大独立集(最大二分匹配)

    Girls and Boys Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  3. hdu 1068 Girls and Boys(匈牙利算法求最大独立集)

    Girls and Boys Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  4. HDU——1068 Girls and Boys

    Girls and Boys Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  5. hdu 1068 Girls and Boys (二分匹配)

    Girls and Boys Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

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

    Girls and BoysTime Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  7. [HDU] 1068 Girls and Boys(二分图最大匹配)

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1068 本题求二分图最大独立点集.因为最大独立点集=顶点数-最大匹配数.所以转化为求最大匹配.因为没有给 ...

  8. hdu 1068 Girls and Boys 二分图的最大匹配

    题目链接:pid=1068">http://acm.hdu.edu.cn/showproblem.php? pid=1068 #include <iostream> #in ...

  9. HDU 1068 Girls and Boys (二分图最大独立集)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1068 有n个同学,格式ni:(m) n1 n2 n3表示同学ni有缘与n1,n2,n3成为情侣,求集合 ...

随机推荐

  1. Python学习(四):模块入门

    1.模块介绍 模块:代码实现的某个功能的集合 模块分类: 自定义模块 内置标准模块 开源模块 模块的常用方法: 是否为主文件:__name__ == '__main__' 如果是直接执行的某程序,那么 ...

  2. Oracle数据库中插入日期型数据(to_date的用法)(转载)

    往Oracle数据库中插入日期型数据(to_date的用法) INSERT  INTO  FLOOR  VALUES  ( to_date ( '2007-12-20 18:31:34' , 'YYY ...

  3. 小白的Python之路 day4 json and pickle数据标准序列化

    一.简述 我们在写入文件中的数据,只能是字符串或者二进制,但是要传入文件的数据不一定全是字符串或者二进制,那还要进行繁琐的转换,然后再读取的时候,还要再转回去,显得很麻烦,今天就来学习标准的序列化:j ...

  4. springBoot系列教程07:异常捕获

    发生异常是很正常的事,异常种类也是千奇百怪,发生异常并不可怕,只要正确的处理,并正确的返回错误信息并无大碍,如果不进行捕获或者处理,分分钟服务器宕机是很正常的事 所以处理异常时,最基本的要求就是发生异 ...

  5. Python第二十一天 fileinput模块

    Python第二十一天    fileinput模块 fileinput模块 fileinput.input([files[, inplace[, backup[, bufsize[, mode[, ...

  6. animate.css – 齐全的CSS3动画库

    animate.css – 齐全的CSS3动画库 演 示 下 载   简介 animate.css 是一个来自国外的 CSS3 动画库,它预设了抖动(shake).闪烁(flash).弹跳(bounc ...

  7. 地址总线、数据总线、寻址能力、字长及cpu位数等概念之间的关系

    地址总线决定了CPU的寻址能力:数据总线的宽度与字长及CPU位数一致. 详细解释见下文: 1.地址总线与寻址能力 要存取数据或指令就要知道数据或指令存放的位置,地址寄存器存储的就是CPU当前要存取的数 ...

  8. 配置不同环境下启用swagger,在生产环境关闭swagger

    前言 Swagger使用起来简单方便,几乎所有的API接口文档都采用swagger了.使用示例:http://www.cnblogs.com/woshimrf/p/swagger.html, 现在开发 ...

  9. IntelliJ IDEA运行项目成功后,无法访问Tomcat主页

    问题 初次使用IntelliJ IDEA,但今天在运行项目启动Tomcat后,发现无法访问Tomcat首页,出现404错误:输入http://localhost:8080时无法访问Tomcat首页,但 ...

  10. ML笔记_机器学习基石01

    1  定义 机器学习 (Machine Learning):improving some performance measure with experience computed from data ...