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. 读取excel到数据库里面

    //读取excel数据到dataTable里面 public DataTable ReadExcelDataToDataTable(string path) { DataTable dt = new ...

  2. C# WPF MVVM 实战 – 5- 用绑定,通过 VM 设置 View 的控件焦点

    本文介绍在 MVVM 中,如何用 ViewModel 控制焦点. 这焦点设置个东西嘛,有些争论.就是到底要不要用 ViewModel 来控制视图的键盘输入焦点.这里不讨论,假设你就是要通过 VM,设置 ...

  3. FJNU 1152 Fat Brother And Integer(胖哥与整数)

    FJNU 1152 Fat Brother And Integer(胖哥与整数) Time Limit: 1000MS   Memory Limit: 257792K [Description] [题 ...

  4. Spark运行在eclipse_使用PyDev和pyspark

    一直想在eclipse上编写Spark程序,但是仿佛是因为spark的安装包提供了PS D:\software\spark-1.6.1-bin-hadoop2.6> .\bin\spark-su ...

  5. 利用[后台]->[类别管理]为文章前后台添加类别名称【转】

    原网址:http://blog.csdn.net/yanhui_wei/article/details/7943176 1.给专题添加文章时,可以选择类别: 2.给文章模型.图片模型.下载模型的栏目下 ...

  6. 从输入 URL 到页面加载完的过程中都发生了什么事情?

    1) 把URL分割成几个部分:协议.网络地址.资源路径.其中网络地址指示该连接网络上哪一台计算机,可以是域名或者IP地址,可以包括端口号:协议是从该计 算机获取资源的方式,常见的是HTTP.FTP,不 ...

  7. 四十条测试你是不是合格的PHP程序员

    四十条测试你是否合格的PHP程序员,不官方,也不权威,但很给力.超过三条就不合格了.超过五条就得好好反省下自己的不足了. 1. 不会利用如phpDoc这样的工具来恰当地注释你的代码 2. 对优秀的集成 ...

  8. iOS - 3DTouch 3D 触摸

    1.3DTouch 简介 3DTouch 是 iOS9 + 系统下,在 iPhone6s(iPhone6s Plus)+ 手机上才能够使用的功能. 1.1 3DTouch 基本类型 1.主屏幕快速选项 ...

  9. HDU5807分段dp

    DAG图. [题意] n(50)个城市m(c(n,2))条单向边(x,y),保证x<y 对于三个点(x,y,z)如果abs(w[x]-w[y])<=K && abs(w[x ...

  10. python下载地址

    https://www.python.org/downloads/release/python-351/