Poj--1466 Girls and Boys
来源:互联网 发布:linux sprintf 编辑:程序博客网 时间:2024/05/17 02:25
<p class="pst">Description</p><div lang="en-US" class="ptx">In 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.</div><p class="pst">Input</p><div lang="en-US" class="ptx">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 (n <=500 ), for n subjects.</div><p class="pst">Output</p><div lang="en-US" class="ptx">For each given data set, the program should write to standard output a line containing the result.</div><p class="pst">Sample Input</p><pre class="sio">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
/*题意大概就是 有n个人 编号0~n-1,人和人之间有直接联系问 最多可以有多少个没有直接联系的人因为一共只有n个人 可以把n变为2*n用匈牙利算法求最大匹配数x最多没有直接联系的人为 n-x/2; */#include<stdio.h>#include<string.h>#include<iostream>using namespace std;int map[510][510];int mark[540];int girl[510];int n;struct node{int next,to;}node[50000];int ans(int i){int j;for(j=0;j<n;j++){if(mark[j]==0&&map[i][j]==1){mark[j]=1;if(girl[j]==-1||ans(girl[j])){girl[j]=i;return 1;}}}return 0;}int main(){int i,j,m,k;while(scanf("%d",&n)!=EOF){memset(map,0,sizeof(map));memset(girl,-1,sizeof(girl));for(k=1;k<=n;k++){scanf("%d: (%d)",&i,&m);while(m--){scanf("%d",&j);map[i][j]=1;map[j][i]=1;}}int x=0;for(i=0;i<n;i++){memset(mark,0,sizeof(mark));x+=ans(i);}//printf("%d",x);printf("%d\n",n-x/2);}}
0 0
- POJ 1466 Girls and Boys
- poj 1466 Girls and Boys
- POJ 1466 Girls and Boys
- POJ-1466-Girls and Boys
- poj 1466 Girls and Boys
- POJ 1466 Girls and Boys
- Poj--1466 Girls and Boys
- POJ 1466 Girls and Boys
- poj 1466 Girls and Boys
- poj 1466 Girls and Boys
- POJ 1466 Girls and Boys
- 【POJ】[1466]Girls and Boys
- poj 1466 Girls and Boys
- POJ 1466 Girls and Boys 二分图
- poj 1466 Girls and Boys (最大独立)
- POJ-1466-Girls and Boys 解题报告
- POJ 1466 Girls and Boys 已翻译
- POJ 1466 Girls and Boys (最大独立集Hungary)
- HDU 1599 find the mincost route (Floyd求最小环) >>
- 使用c语言对mysql进行增删查改
- Hibernate 自动生成 hbm文件
- 间谍猫的娱乐:wifi设置,你太弱了
- linux ln 命令使用参数详解(ln -s 软链接)
- Poj--1466 Girls and Boys
- XSL
- ListView、GridView显示加动画
- 一些好的Android开源项目
- haproxy负载均衡服务器之搭建
- hdu-2795 Billboard
- 怎样破坏程序的堆栈?
- 24点游戏(粗判是否成立)
- CmakeLists.txt文档的使用