Girls and Boys

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

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
二分图求最大独立集:
最大独立集==节点数-最大匹配数
#include<stdio.h>
#include<string.h>
#define MAX 1100
int vis[MAX],map[MAX][MAX],stu[MAX];
int t;
int find(int x)
{
int i;
for(i=0;i<t;i++)
{
if(map[x][i]&&vis[i]==0)
{
vis[i]=1;
if(stu[i]==0||find(stu[i]))
{
stu[i]=x;
return 1;
}
}
}
return 0;
}
int main()
{
int n,m,i,j,sum,a,b;
while(scanf("%d",&t)!=EOF)
{
memset(stu,0,sizeof(stu));
memset(map,0,sizeof(map));
for(i=0;i<t;i++)
{
scanf("%d: (%d)",&a,&n);
while(n--)
{
scanf("%d",&b);
map[a][b]=1;
}
}
sum=0;
for(i=0;i<t;i++)
{
memset(vis,0,sizeof(vis));
if(find(i))
sum++;
}
printf("%d\n",t-sum/2);
}
return 0;
}

hdoj 1068 Girls and Boys【匈牙利算法+最大独立集】的更多相关文章

  1. POJ 1466 Girls and Boys (匈牙利算法 最大独立集)

    Girls and Boys Time Limit: 5000MS   Memory Limit: 10000K Total Submissions: 10912   Accepted: 4887 D ...

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

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

  3. (step6.3.2)hdu 1068(Girls and Boys——二分图的最大独立集)

    题目大意:第一行输入一个整数n,表示有n个节点.在接下来的n行中,每行的输入数据的格式是: 1: (2) 4 6 :表示编号为1的人认识2个人,他们分别是4.6: 求,最多能找到多少个人,他们互不认识 ...

  4. hdu1068 Girls and Boys 匈牙利算法(邻接表)

    #include <cstdio> #include <algorithm> #include <cstring> #include <vector> ...

  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 Boys Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  7. 【HDOJ】1068 Girls and Boys

    匈牙利算法,最开始暴力解不知道为什么就是wa,后来明白,一定要求最优解.查了一下匈牙利算法相关内容,大致了解. #include <stdio.h> #include <string ...

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

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

  9. poj 1466 Girls and Boys(二分图的最大独立集)

    http://poj.org/problem?id=1466 Girls and Boys Time Limit: 5000MS   Memory Limit: 10000K Total Submis ...

随机推荐

  1. webstorm快捷方式

    刚开始在使用webstrom的时候,不知道快捷方式,感觉自己把webstorm当做记事本使用,真的挺傻的,在朋友的指导下,原来webstorm有快捷方式 一.界面操作 快捷键 说明 ctrl+shif ...

  2. 响应式页面字体用什么单位:rem

    html:62.5%//10pxbody:1.4rem;//14px... <!doctype html> <html> <head> <title>a ...

  3. sae后台管理端的js,daterangepicker使用

    原本只为了日期范围选择器看下sae的前端怎么实现 然后... 公共函数两个文件,第一个是各种插件: typeahead.js 自动完成 //关键词自动完成 $('#page-auto-complete ...

  4. 犯这个错误的肯定不止我一个 关于File

    File.Create(string filePath)这种用法所有人都知道,这两天用到的时候却发现一个问题. 需要先判断文件是否存在,如果不存在则创建文件,然后向该文件写入数据,后续定时Append ...

  5. 传感器- 加速计 - CoreMotion

    /** *  CoreMotion * */ #import "ViewController.h" #import <CoreMotion/CoreMotion.h> ...

  6. java 异常小结

    异常大体分为编译异常和运行异常两类,如果用软件开发(如Eclipse)编译异常在写代码时得到提醒, 而运行异常需要在运行时才能得到提示. 算术异常类:ArithmeticExecption 这个异常是 ...

  7. DataGrid点击上下一页loading效果

    js添加显示loading和取消loading方法 function showtbloading() { var target = $("#GridView1"); if (tar ...

  8. PYTHON--CLASS

    class Robot: population = 0 def __init__(self, name): self.name = name print("(Initializing {0} ...

  9. 力控ADO组件数据源设置

    1.mysql的ODBC驱动如何下载及安装 地址:http://dev.mysql.com/downloads/connector/odbc/5.1.html Mysql跟力控ado进行交互 第一步: ...

  10. VS2013 ASP.NET MVC 修改Web项目的IISExpress的端口固定

    [首先]关闭防火墙,或防火墙开放端口  在解决方案中,右键某项目,属性——Web——服务器——选择IISExpress URL输入:http://localhost:8000/   直接将8000更改 ...