HDOJ 1068 Girls And Boys (最大独立集数)
来源:互联网 发布:qt程序员常用单词 编辑:程序博客网 时间:2024/05/19 04:55
原题链接
一、题目描述
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
二、题目分析
二分匹配的变形。利用结论 二分图的最大独立集数 = 节点数 - 最大匹配数。
三、AC代码
#include <iostream>#include <cstring>using namespace std;const int M = 500;int MAP[M][M];int line[M];bool used[M];int n, m, ans;bool findx(int x) { for(int i = 0; i < n; i++) { if(MAP[x][i] && !used[i]) { used[i] = true; if(line[i] == -1 || findx(line[i])) { line[i] = x; return true; } } } return false;}int main() { while (cin >> n) { ans = 0; memset(MAP, 0, sizeof(MAP)); memset(line, -1, sizeof(line)); for(int i = 0; i < n; i++) { /*getchar();getchar();getchar();getchar(); cin >> m; getchar();*/ int hh; scanf("%d: (%d)", &hh, &m); for(int j = 0; j < m; j++) { int tmp; cin >> tmp; MAP[i][tmp] = 1; } } for(int i = 0; i < n; i++) { memset(used, 0, sizeof(used)); if(findx(i)) ans++; } //cout << ans << endl; cout << n - ans/2 << endl; //因为输入数据是双向的,比如有1-->6,就有6-->1,所以ans/2. } return 0;}
阅读全文
0 0
- HDOJ 1068 Girls And Boys (最大独立集数)
- 【hdu 1068 Girls and Boys 最大独立集数 匈牙利算法 】
- 【HDU1068】Girls and Boys(最大独立集数,匈牙利算法)
- hdoj--1068--Girls and Boys(最大独立集)
- HDU 1068 Girls and Boys (匈牙利算法 二分图的最大独立集数 )
- 【杭电oj】1068 - Girls and Boys(最大独立集数,匈牙利算法)
- HDOJ题目1068Girls 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 二分最大独立集
- HDU 1068 Girls and Boys 最大独立集
- hdu 1068 Girls and Boys(最大独立集)
- HDU 1068 boys and girls(最大独立集)
- HDU 1068 Girls and Boys(最大独立集合)
- hdu 1068 Girls and Boys 【最大独立集】
- HDU 1068 — Girls and Boys 最大独立集
- bzoj1668 [Usaco2006 Oct]Cow Pie Treasures 馅饼里的财富
- 关于UIView的autoresizingMask属性的研究
- KMP
- 关于线程
- C语言中的 linux 信号
- HDOJ 1068 Girls And Boys (最大独立集数)
- 消息中间件RabbitMQ 初探
- JPush极光推送Java服务器端实例
- [vim]怎样记忆 进入编辑模式的按键
- Python算法--计数初步
- HtmlUnit自动填写表单并提交
- phono 问题
- JAVA实现图片叠加效果
- uva12657 Boxes in a Line 双向链表