Girls and Boys

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

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<cstring>
#include<cstdio>
#include<cstdlib>
using namespace std;
const int maxn=;
int n,a,b,c;
bool mat[maxn][maxn];
bool vis[maxn];
int girl[maxn];
bool check(int x){
for(int i=;i<n;i++){
if(mat[x][i]==&&!vis[i]){
vis[i]=;
if(girl[i]==-||check(girl[i])){
girl[i]=x;
return ;
}
}
}
return ;
}
int main()
{
//freopen("test.in","r",stdin);
while(scanf("%d",&n)!=EOF){
memset(mat,,sizeof(mat));
memset(girl,-,sizeof(girl));
for(int i=;i<n;i++){
scanf("%d: (%d)",&a,&b);
while(b--){
scanf("%d",&c);
mat[a][c]=;
}
}
int ans=;
for(int j=;j<n;j++){
memset(vis,,sizeof(vis));
if(check(j))ans++;
}
/*通过最大二分匹配,我们得到了最大匹配数,但是由于男生女生
都算了一遍,所以是不是就得除以二。这样就是最大匹配数了*/
printf("%d\n",n-ans/);
}
return ;
}
 

hduoj-----(1068)Girls and Boys(二分匹配)的更多相关文章

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

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

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

    题意:给出每个学生的标号及与其有缘分成为情侣的人的标号,求一个最大集合,集合中任意两个人都没有缘分成为情侣. 分析: 1.若两人有缘分,则可以连一条边,本题是求一个最大集合,集合中任意两点都不相连,即 ...

  3. hdu1068 Girls and Boys 二分匹配

    题目链接: 二分匹配的应用 求最大独立集 最大独立集等于=顶点数-匹配数 本体中由于男孩和女孩的学号是不分开的,所以匹配数应是求得的匹配数/2 代码: #include<iostream> ...

  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 最大独立点集 二分匹配

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1068 思路: 求一集合满足,两两之间没有恋爱关系 思路: 最大独立点集=顶点数-最大匹配数 这里给出的 ...

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

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

  7. hdoj 1068 Girls and Boys【匈牙利算法+最大独立集】

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

  8. HDU——1068 Girls and Boys

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

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

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

随机推荐

  1. Cheatsheet: 2013 06.23 ~ 06.30, Farewell GoogleReader(2008.07.20~2013.06.30)

    Mobile Resources for Mac and iOS Developers- Introduction to Objective-C Modules Other 10 Principles ...

  2. COM/ATL 资料收集

    COM/ATL COM基础知识 COM技术分类

  3. iOS开发学习笔记:基础篇

    iOS开发需要一台Mac电脑.Xcode以及iOS SDK.因为苹果设备都具有自己封闭的环境,所以iOS程序的开发必须在Mac设备上完成(当然,黑苹果应该也是可以的,但就需要花很多的精力去折腾基础环境 ...

  4. [SAP ABAP开发技术总结]Form(subroutine)、Function参数传值传址

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  5. [JAVA设计模式]第三部分:结构模式

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  6. How to crack interviews ...

    Code practice: Leetcode: www.leetcode.com HackerRank: www.hackerrank.com Topcoder: https://www.topco ...

  7. python_way ,day22 tonardo

    python_way day22 1.tonardo 2.cookie 3.api认证 一.tonardo: a.tonardo 初识 #!/usr/bin/env python3# Created ...

  8. Backbone简介

    backbone-------一个实现了web前端MVC模式的JS库-------官方地址 backbone库要建立在underscore库的基础上---------------官方中文地址----- ...

  9. css 集锦。

    可以是 链接的下划线 去掉. a {text-decoration: none} position:absolute 绝对定位 position:relative 相对定位  ie  图片失真 -ms ...

  10. 大学生学习编程(PHP)

    在v2ex上看到一大三的求职实习,然后有人给出了建议,个人觉得也挺好,做个记录./  原帖地址 @ARjson问: 大三的学生党,求实习岗位,现居北京.后端PHP一年半开发经验,熟悉speedphp, ...