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. 【Unity3D游戏开发】定制新建C#文件的头描述 (三三)

    unity添加新脚本的时候,可以定制[开发者姓名][开发日期][文件描述][版权声明]等,省的到时候不知道谁写的,也没有个描述,关键是TNND连个背锅的人都没有 其实unity已经给我们提供了新建脚本 ...

  2. DevExpress Crack

    开发者论坛 DevExpressComponents-16.1.6.16270.exe http://www.dxper.net/thread-7440-1-1.html http://www.dxp ...

  3. U盘文件后缀变成.exe怎么办?

    现在U盘病毒90%都是kido病毒,中了kido病毒的U盘文件名会变成可执行文件,后缀带有exe,虽然杀毒软件可以杀掉,但都是没办法处理它的母体,由于此类文件并没有丢失,而是被隐藏了,因此我们可以靠手 ...

  4. Java中正则表达式的使用

    public class Test{ public static void main(String args[]) { String str="@Shang Hai Hong Qiao Fe ...

  5. [SAP ABAP开发技术总结]列表屏幕

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

  6. Android SDK 更新镜像服务器

    搞个新的电脑,新环境下,SDK总是更新不成功.找了一下,发现有国内的镜像,记录保存一下. Android Tools Android SDK在线更新镜像服务器    中国科学院开源协会镜像站地址:   ...

  7. php wamp 配置虚拟主机

    apeach  配置: 还有是:E:\wamp\bin\apache\Apache2.4.4\conf 目录下有个 http.conf文件中,有一个需要取消注释, # Virtual hostsInc ...

  8. TreeView控件

    public partial class WebForm1 : System.Web.UI.Page { DataSet dsTreeView = new DataSet(); protected v ...

  9. Scrum Meeting---One(2015-10-20)

    一.scrum meeting 在上周六我们团队进行了一次会议,讨论了我们团队的项目以及项目分工.首先是确立我们的项目,在团队的激烈讨论下我们决定做一个校园相关的APP.然后对于这个项目我们大致进行了 ...

  10. WDS 的两种实现方式

    转自:http://blog.chinaunix.net/uid-26527046-id-3627627.html WDS 的两种实现方式 WDS(Wireless Distribution Syst ...