【HDU OJ 1068】Girls and Boys
来源:互联网 发布:淘宝花呗卖家开通条件 编辑:程序博客网 时间:2024/06/04 20:44
B - Girls and Boys
Time Limit:10000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64uDescription
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
注意:题目中说的是集合中的人一定没有互相配对,所以求得时候一定注意配对的人只能有一个人在set中
AC代码:
#include<cstdio>#include<algorithm>#include<cstring>using namespace std;int fr[505][505];int f[505];bool vis[505];int k;bool find(int x){for(int i = 0; i < k; i++){if(fr[x][i]&&!vis[i]){vis[i]=1;if(f[i]==-1){f[i]=x;return 1;}elseif(find(f[i])){f[i]=x;return 1;}}}return 0;}int main(){while(~scanf("%d",&k)){memset(fr,0,sizeof(fr));memset(f,-1,sizeof(f));for(int i = 0; i < k; i++){int x,p,y;scanf("%d: (%d)",&x,&p);if(p){for(int j = 0; j < p; j++){scanf("%d",&y);fr[x][y]=1;}}}int ans=0;for(int i=0;i<k;i++){memset(vis,0,sizeof(vis));if(find(i)){ans++;}}ans=k-ans/2;printf("%d\n",ans);}return 0;}
阅读全文
0 0
- 【HDU OJ 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 Girls and Boys
- hdu 1068 Girls and Boys
- HDU 1068Girls and Boys
- HDU 1068 Girls and Boys
- hdu 1068 Girls and Boys
- 【hdu 1068】Girls and Boys
- Girls and Boys HDU
- hdu 1068 Girls and Boys 二分匹配
- hdu 1068 Girls and Boys 解题报告
- hdu 1068 Girls and Boys 匈牙利
- hdu 1068 Girls and Boys (二分匹配)
- PDO事务实例
- 哥德巴赫猜想
- Groovy 基本类型
- 加权随机数
- 安装pip最简单的方法
- 【HDU OJ 1068】Girls and Boys
- Libevent简介
- caffe+CUDA 8.0+matlab R2015b的安装过程
- ArcGIS Server安装及地图服务发布
- HDOJ1142 A Walk Through the Forest
- 面向对象的5大基本原则
- 线上服务CPU100%问题快速定位实战(58沈剑)
- 简单工厂
- 数组中的逆序对