杭电1068 Girls and Boys
来源:互联网 发布:家庭网络如何共享 编辑:程序博客网 时间:2024/05/24 07:33
这是一道二分图的题,把男生女生都看作是两集合里的数,因为两集合中都是所有的人,他们的缘分是双向的,最后搜出来的最大匹配数除以二。由最大独立集=顶点数-最大匹配数,求出最大独立集!!!
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.
70: (3) 4 5 61: (2) 4 62: (0)3: (0)4: (2) 0 15: (1) 06: (2) 0 130: (2) 1 21: (1) 02: (1) 0
52
//杭电1068
#include<iostream>
using namespace std;
bool map[1002][1002],visit[1002];
int match[1002];
int n;
bool dfs(int k)
{
int i;
for(i=0;i<n;i++)
{
if(map[k][i] && !visit[i])
{
visit[i]=true;
if(match[i]==-1 || dfs(match[i]))
{
match[i]=k;
return true;
}
}
}
return false;
}
int main()
{
int k,b,l,i;
int s;
while(scanf("%d",&n)!=EOF)//总共有n个人
{
s=0;
memset(map,false,sizeof(map));
memset(match,-1,sizeof(match));
for(i=0;i<n;i++)
{
scanf("%d: (%d)",&l,&k); //l所输入人的编号
//该人有k个有缘人
while(k--)
{
scanf("%d",&b);
map[l][b]=true;
}
}
for(i=0;i<n;i++)
{
memset(visit,false,sizeof(visit));
if(dfs(i))
s++;
}
s=n-s/2; //最大独立集=顶点数-最大匹配数/2(因为两个集合都是全部人数,他们的缘分是双向的,所以搜出的最大匹配数要除以2)
printf("%d\n",s);
}
return 0;
}
- 杭电1068 Girls and Boys
- 杭电1068-Girls and Boys
- 杭电OJ——1068 Girls and Boys(二分图)
- 杭电1068 (二分图的独立点集)Girls and Boys
- 【杭电oj】1068 - Girls and Boys(最大独立集数,匈牙利算法)
- HDOJ 1068 Girls and Boys
- HDU-1068 Girls and Boys
- hdoj 1068 Girls and Boys
- HDOJ 1068 Girls and Boys
- hdoj 1068 Girls and Boys
- hdu 1068 Girls and Boys
- hdu 1068 Girls and Boys
- hdu 1068 Girls and Boys
- HDU 1068 Girls and Boys
- hdu 1068 Girls and Boys
- hdoj 1068 Girls and Boys
- HDU 1068 Girls and Boys
- 【HDOJ 1068】Girls and Boys
- 在校生如何开始学习数据库(五) oracle数据学习总结
- SquashFS Howto
- java中file与io概述
- Oracle中自动获取序列sequence用法
- pivotGridControl 获取行头
- 杭电1068 Girls and Boys
- method overloading
- java comm v3 的安装 ubuntu
- mongodb在nodejs上基本应用
- HDOJ2888-裸二维RMQ
- 20120813 i2000上面一个表空间满了,被索引占了
- Change Log 前世今生
- div+css 列表
- iOS5 ARC学习笔记