Girls and Boys
来源:互联网 发布:thomson数据库 编辑:程序博客网 时间:2024/06/01 09:49
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
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int f[520];int fr[520][520];bool vis[520];int t;bool find(int x){ for(int i = 0; i < t; i++) { if(fr[x][i] && !vis[i]) { vis[i] = true; if(f[i] == -1) { f[i] = x;return true; } else if( find( f[i] ) ) { f[i] = x;return true; } } }return false;}int main(){ while(~scanf("%d",&t)) { memset(fr , 0 ,sizeof(fr)); memset(f , -1 , sizeof(f)); for(int i = 0; i < t; i++) { int x , m; scanf("%d: (%d)",&x , &m); while(m--) { int y; scanf("%d",&y); fr[x][y] = 1; fr[y][x] = 1; } } int ans = 0; for(int i = 0 ; i < t; i++) { memset(vis , false , sizeof(vis)); if( find(i) ) ans++; } int sum; sum = t - ans/2; printf("%d\n",sum); }return 0;}
阅读全文
0 0
- Girls and Boys
- hdu1068 Girls and Boys
- Girls and Boys
- zoj1137:Girls and Boys
- poj1466 - Girls and Boys
- hdu1608 Girls and Boys
- A. Boys and Girls
- HDU1068--Girls and Boys
- HDU1068:Girls and Boys
- HDU1068-Girls and Boys
- poj1466--Girls and Boys
- POJ1466 Girls and Boys
- Girls and Boys
- Girls and Boys
- Girls and Boys
- poj1466 Girls and Boys
- Girls and Boys
- Girls and Boys
- 不用手机号码怎么注册微信号
- 接口的调用与调用别人的接口
- 动态规划 背包问题 poj 1837 Balance
- 工程师的调试法宝之Printf串口输出
- 51nod1277 字符串中的最大值(KMP)
- Girls and Boys
- JAVA学习笔记_利用slf4j进行log4j日志管理
- oracle学习历程 2017/8/21
- 浏览器支持的几种URL
- 【计算机网络】计算机网络的性能
- 二进制、源码安装的方式mysql卸载
- Kotlin 初窥门径[1]-基础概念
- Asteroids
- Docker提交本地镜像