HDU1068 二分图 最大独立集
来源:互联网 发布:拼图软件 编辑:程序博客网 时间:2024/05/22 18:22
0)
题意:有人互相喜欢,则被认为是恋爱关系,如果我们去掉一些人,使得剩下的人都找不出互相喜欢的,那么剩下的人最多是多少呢?
分析:去掉一些人,去掉的是,经过选择,能形成最多的互相喜欢的情侣对,并从这些情侣对中每对去掉一个人,剩下的单身人数自然最多。这是个求最大独立点集的问题,最大独立点集=节点数-最大匹配数。
注意:之前总是错,是因为在全局中int n,而在局部中,又int n,结果出现了错误,因为局部变量有优先性!
1)
#include <iostream>#include <stdio.h>#include <string.h>//cur 从0开始样例不过!!??using namespace std;const int maxn=1010;//int mat[maxn][maxn];int node[maxn][maxn];int used[maxn];int head[maxn];int link[maxn*maxn];int n;int dfs(int a){ for(int i=0;i<n;i++){ if(!used[i]&&node[a][i]){ used[i]=1; if(link[i]==-1||dfs(link[i])){ link[i]=a; return 1; } } } return 0;}int hungary(){ int sum=0; memset(link,-1,sizeof(link));//从-1开始就是避免数据是从0开始的!!! for(int i=0;i<n;i++){ memset(used,0,sizeof(used)); if(dfs(i)){ sum++; } } return sum;}int main(){ //int n; 局部变量优先!!! int i,j,num,a,b; while(~scanf("%d",&n)){ //memset(mat,-1,sizeof(mat)); //int id,num,id2; //char str; //cur=1; memset(node,0,sizeof(node)); for(i=1;i<=n;i++){ scanf("%d: (%d)",&a,&num); for(int j=0;j<num;j++){ scanf("%d",&b); node[a][b]=1; } } //cout<<"s"<<endl; int cnt=hungary(); //cout<<cnt<<endl; cout<<n-cnt/2<<endl; } return 0;}
2)
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
0 0
- hdu1068 二分图的最大独立集
- HDU1068 二分图 最大独立集
- hdu1068【二分图最大独立集】
- hdu1068-二分图最大独立集
- hdu1068 Girls and Boys (二分图最大独立集)
- HDU1068-Girls and Boys(二分图_最大独立集)
- hdu1068 Girls and Boys,二分图最大独立集
- hdu1068 二分图最大独立子集
- hdu1068 二分图最大独立子集
- HDU1068/POJ1466_Girls and Boys(二分图/最大独立集=N-最大匹配)
- 二分匹配最大独立集——hdu1068
- HDU1068 二分匹配 独立集
- HDU1068,POJ1466——Girls and Boys(二分图最大独立集)
- hdu1068||poj1466(最大独立集)
- HDU1068 (最大独立集)
- hdu1068 Girls and Boys 最大独立集
- hdu1068 Girls and Boys最大独立集
- hdu1068 Girls and Boys 最大独立集
- Stanford 机器学习 Anomaly Detection
- hihoCoder1301 筑地市场(统计符合条件数字,数位dp)
- 匈牙利算法模板及解释
- Hibernate中的级联策略和object references an unsaved transient instance - save the transient instance before
- windows命令行启动虚拟机(VirtualBox、VMware)
- HDU1068 二分图 最大独立集
- Android Studio报错,Error:SSL peer shut down incorrectly
- 图像处理之高斯金字塔
- vim查找替换
- 交换两个值函数swap()实现小结
- Java中的Set与hashCode
- 最大似然估计(MLE)和最大后验概率(MAP)
- 如何使用控制台操作数据库
- 贪心算法