杭电OJ——1068 Girls and Boys(二分图)
来源:互联网 发布:吕丽萍反对同性恋知乎 编辑:程序博客网 时间:2024/06/03 15:29
Girls and Boys
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.
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
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
Sample Output
52
Source
Southeastern Europe 2000
Recommend
JGShining
方法:最大独立集、最大匹配
思想:
最大独立集指的是两两之间没有边的顶点的集合,顶点最多的独立集成为最大独立集。二分图的最大独立集=节点数-(减号)最大匹配数。
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"。
本题中给出的是同学之间的亲密关系,并没有指出哪些是男哪些是女,所以求出的最大匹配数
要除以2才是真正的匹配数。
关于匈牙利算法:http://blog.csdn.net/lishuhuakai/article/details/8123878
发代码:
//关于题目意思的理解:二分图的匹配问题,题目给出了同学之间的亲密关系,没有指出是男是女//匈牙利算法!又遇到过这种算法//先敲一段匈牙利算法!#include<iostream>using namespace std;const int Max=500;int num;int g[Max][Max];int linker[Max];bool used[Max];bool dfs(int u){int v;for(v=0;v<num;v++){if(g[u][v] && !used[v]){used[v]=true;if(linker[v]==-1 || dfs(linker[v])){linker[v]=u;return true;}}}return false;}int hungary(){int res=0;int u;memset(linker,-1,sizeof(linker));for(u=0;u<num;u++){memset(used,0,sizeof(used));if(dfs(u)) res++;}return res;}int main(){int a,b,c;int cases;while(scanf("%d",&cases)!=EOF){num=cases;int m;memset(g,0,sizeof(g)); while(cases--) { scanf("%d: (%d)",&a,&b); for(int i=0;i<b;i++) { scanf("%d",&c); g[a][c]=1; } } printf("%d\n",num-hungary()/2); }return 0;}
- 杭电OJ——1068 Girls and Boys(二分图)
- 杭电1068 (二分图的独立点集)Girls and Boys
- 【杭电oj】1068 - Girls and Boys(最大独立集数,匈牙利算法)
- 杭电1068 Girls and Boys
- 杭电1068-Girls and Boys
- HDU 1068 Girls and Boys 二分图
- hdoj 1068 Girls and Boys<二分图>
- Girls and Boys(二分图)
- hdu1068 Girls and Boys(二分图)
- hdu 1068 Girls and Boys (二分图匹配)
- hdu 1068 Girls and Boys(水题,二分图匹配)
- HDU 1068 Girls and Boys(二分图最大匹配)
- 【HDU 1068】Girls and Boys(二分图)
- Girls and Boys(二分图)
- (step6.3.2)hdu 1068(Girls and Boys——二分图的最大独立集)
- HDU1068,POJ1466——Girls and Boys(二分图最大独立集)
- 【HDU OJ 1068】Girls and Boys
- 【图算法之二分图】HDU 1068---Girls and Boys
- erlang学习路线图
- Maven总结
- Spring aop之注解方式
- Liferay hook works with external customized jar which is built by Spring
- 07_班级静态网页设计(小钱版)[Web开发][2012-11-20]
- 杭电OJ——1068 Girls and Boys(二分图)
- Android怎样播放多张图片形成一个动画
- spring aop 之配置方式
- Android中实现图片的拖拽显示
- Jugs_1005
- Maven总结
- java 类与对象 1---static关键字
- 电子方向开发工程师的职场人生路(转)
- 零碎python学习笔记(四) - 20121211 - 函数修饰符@