题目链接:

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. Redis分布式集群搭建

    Redis集群架构图 上图蓝色为redis集群的节点. 节点之间通过ping命令来测试连接是否正常,节点之间没有主区分,连接到任何一个节点进行操作时,都可能会转发到其他节点. 1.Redis的容错机制 ...

  2. avro 1.8.2 (js)

    5月15日发布的avro 1.8.2 已经包含了js版代码. 清华大学镜像地址: https://mirrors.tuna.tsinghua.edu.cn/apache/avro/avro-1.8.2 ...

  3. C语言学生管理系统(增进版)

    在原版上进行改进,主要改进的功能有. 1.利用atof:将字符串转换为浮点型: 利用atoi:将字符串转换为整型: 原文地址:http://www.cnblogs.com/sddai/p/577412 ...

  4. 只要发生ajax请求时加载旋转的按钮

    定义一个变量 全局 c 只要发生ajax时给c++ 当ajax请求success或者error时,c--; 对加载的按钮添加个事件   监听 c  如果c得值没变化  则隐藏按钮   如果变化了则显示 ...

  5. 解决myeclipse部署按钮不能点

    找到MyEclipse的工作路径(一般点开myeclipse是会显示),然后到这个目录中去“\.metadata\.plugins\org.eclipse.core.runtime\.settings ...

  6. css条纹背景

    一. 水平条纹 1. 两种颜色: html <div class="stripe"></div> css .stripe{ width: 250px; he ...

  7. android开发文章收藏

    1.activity [Android的从零单排开发日记]之入门篇(四)——Android四大组件之Activity 两分钟彻底让你明白Android Activity生命周期(图文)! 2.serv ...

  8. Oracle误删数据文件后出现oracle initialization or shutdown in progress解决

    一.错误分析 1.首先本人在出现这种情况的背景是执行如下SQL语句后生成的表空间 --自定义表空间 数据表空间 临时表空间 CREATE TEMPORARY TABLESPACE HOUSE_TEMP ...

  9. socket模型处理多个客户端

    最近学完了简单的socket编程,发现其实socket的网络编程其实并没有什么难度,只是简单的函数调用,记住客户端与服务端的步骤,写起来基本没有什么问题. 在服务器程序的设计中,一个服务器不可能只相应 ...

  10. JS 获取字符串实际长度

    解决思路,把中文转换为两个字节的英文,再计算长度. function getStrLength(str) { return str.replace(/[\u0391-\uFFE5]/g,"a ...