【图算法之二分图】HDU 1068---Girls and Boys
来源:互联网 发布:海思科技人工智能 编辑:程序博客网 时间:2024/05/29 07:24
Girls and Boys
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2289 Accepted Submission(s): 992
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
题意:就是求出剩余的最少的无关组数(总组数减去情侣总数)。因为题中没告知是男还是女,所以最后求出的最大组数
应该除以二。
#include<stdio.h>#include<string.h>int map[501][501],flag[501],pre[501],num;int get(int i){ int j,k,l; for(j=0;j<num;j++) { if(map[i][j]&&flag[j]==0) { flag[j]=1; if(pre[j]==-1||get(pre[j])) { pre[j]=i; return 1; } } } return 0;}int main(){ int l,r,i,ll,j,k; while(~scanf("%d",&num)) { memset(map,0,sizeof(map)); memset(pre,-1,sizeof(pre)); for(i=0;i<num;i++) { scanf("%d: (%d)", &k, &ll); for(j=0;j<ll;j++) { scanf("%d",&r); map[i][r]=1; } } int sum=0; for(int i=0;i<num;i++) { memset(flag,0,sizeof(flag)); sum+=get(i); } printf("%d\n",num-sum/2); } return 0;}
0 0
- 【图算法之二分图】HDU 1068---Girls and Boys
- HDU 1068 Girls and Boys 二分图
- Girls and Boys(二分图--匈牙利算法)
- 【图算法之二分图】HDU1068---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 【二分图+增广路】
- HDU 1068 Girls and Boys(二分图最大匹配)
- hdu 1068 Girls and Boys 二分图的最大匹配
- 【hdu 1068 基础二分图】Girls and Boys
- 【HDU 1068】Girls and Boys(二分图)
- hdoj 1068 Girls and Boys 【匈牙利算法&&二分图匹配】
- HDU 1068 Girls and Boys (匈牙利算法 二分图的最大独立集数 )
- HDU 1068 Girls and Boys(二分图匹配+最大独立集+匈牙利算法)
- hdoj 1068 Girls and Boys<二分图>
- 选择排序C语言实现
- 中药将不可避免走向没落
- [LeetCode]-Letter Combinations of a Phone Number 电话键盘的字符串组合
- 在Sandbox中调用系统工具的问题
- Android 4.4 apk安装到桌面生成icon过程
- 【图算法之二分图】HDU 1068---Girls and Boys
- onInterceptTouchEvent和onTouchEvent调用时序
- 用 DBMS_SCHEDULER 代替 DBMS_JOB
- C++基础之内联函数
- 电容参数:X5R,X7R,Y5V,COG 详解
- 使用HAProxy、PHP、Redis和MySQL支撑每天上亿请求的架构细节
- oracle学习之体系结构2
- PHP-Date()
- iOS实用技巧 - AFNetworking2安全的使用自签证书访问HTTPS