二分图最大独立集 二维动态数组 杭电1068
来源:互联网 发布:双卡如何选择网络 编辑:程序博客网 时间:2024/06/12 18:56
点击打开链接
Girls and Boys
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 12171 Accepted Submission(s): 5734
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 | We have carefully selected several similar problems for you: 1150 1151 1281 1507 1528
做这题需要知道最大独立点集=点数—二分图最大匹配对数,还有一点是这题没有男女分开编号,是混着的所以最后需要除以二才是最大匹配对数
代码如下:
#include<cstdio>#include<cstring>#include<vector>#include<algorithm>using namespace std;int f[505],vis[505];vector<int>ss[505]; //用到二维动态数组 int n,m,k;char s;bool find (int x){for(int j = 0; j<ss[x].size(); j ++){ if(!vis[ss[x][j]]) { vis[ss[x][j]]=1; if(f[ss[x][j]]==-1||find(f[ss[x][j]])) { f[ss[x][j]]=x; return true;}}}return false;}int main(){while(~scanf("%d",&n))//学生人数 {memset(f,-1,sizeof(f));memset(ss,0,sizeof(ss));for(int i = 0; i <n; i ++){scanf("%d%c (%d)",&m,&s,&k);//学号 冒号 喜欢的人数 while(k--){int a;scanf("%d",&a);//喜欢的人的学号 ss[m].push_back(a); }}int sum=0;for(int i = 0; i < n; i ++){memset(vis,0,sizeof(vis));if(find(i))sum++;}printf("%d\n",n-sum/2);}return 0;}
阅读全文
0 0
- 二分图最大独立集 二维动态数组 杭电1068
- poj 1068(二分图最大独立集)
- hdu 1068(二分图最大独立集)
- hdu 1068 二分图 最大独立集
- 二分图最大独立集
- 二分图最大独立集
- 二分图最大独立集
- 二分图最大匹配 & 最大独立集
- hdu 1068 极大独立集 二分图最大匹配
- 杭电1068 (二分图的独立点集)Girls and Boys
- hdu 3829 二分图最大独立集
- poj 2771 二分图最大独立集
- HDU2768二分图求最大独立集
- poj3692 Kindergarten 二分图最大独立集
- hdu4160 Dolls (二分图最大独立集)
- poj 1466 二分图 最大独立集
- 二分图最大独立集--poj2771
- 二分图最大独立集-poj1466
- FreeMarker入门笔记三之spring整合
- ffmpeg解码的几种方法
- SVN版本管理系统的安装
- MySQL必知必会 学习笔记 四
- 深入浅出TensorFlow(六)TensorFlow高层封装
- 二分图最大独立集 二维动态数组 杭电1068
- scala常见语法,供以后参考(2017年8月20号)
- Telnet基本介绍(1)
- 石子合并(一) 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 有N堆石子排成一排,每堆石子有一定的数量。现要将N堆石子并成为一堆。合并的过程只能每次将相邻的两堆
- java基础----网络编程 tcp
- leetcode-14 commonPrefix
- web前端知识总结3
- 深入浅出TensroFlow(七)TensorFlow计算加速
- hodoop伪分布配置详细步骤