poj 1466 Girls and Boys 最大独立集=n-最小覆盖点
来源:互联网 发布:淘宝代销退货地址哪里 编辑:程序博客网 时间:2024/05/30 02:24
Description
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.
Input
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.
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.
Output
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
Source
Southeastern Europe 2000
#include<stdio.h>
#include<string.h>
bool Map[550][550];
bool Flag[550];
int Mark[550];
bool Find(int x,int n)
{
int i;
for(i=1;i<=n;i++)
{
if(!Map[x][i]||Flag[i])
continue;
Flag[i]=true;
if(!Mark[i]||Find(Mark[i],n))
{
Mark[i]=x;
return true;
}
}
return false;
}
int main()
{
int n;
int i,j;
int t;
int x,y;
int Count;
while(scanf("%d",&n)!=EOF)
{
memset(Map,false,sizeof(Map));
memset(Mark,0,sizeof(Mark));
for(i=1;i<=n;i++)
{
scanf("%d: ",&x);
scanf("(%d)",&t);
for(j=1;j<=t;j++)
{
scanf("%d",&y);
Map[x+1][y+1]=true;
}
}
Count=0;
for(i=1;i<=n;i++)
{
memset(Flag,false,sizeof(Flag));
if(Find(i,n))
Count++;
}
printf("%d\n",n-Count/2);
}
return 0;
}
#include<string.h>
bool Map[550][550];
bool Flag[550];
int Mark[550];
bool Find(int x,int n)
{
int i;
for(i=1;i<=n;i++)
{
if(!Map[x][i]||Flag[i])
continue;
Flag[i]=true;
if(!Mark[i]||Find(Mark[i],n))
{
Mark[i]=x;
return true;
}
}
return false;
}
int main()
{
int n;
int i,j;
int t;
int x,y;
int Count;
while(scanf("%d",&n)!=EOF)
{
memset(Map,false,sizeof(Map));
memset(Mark,0,sizeof(Mark));
for(i=1;i<=n;i++)
{
scanf("%d: ",&x);
scanf("(%d)",&t);
for(j=1;j<=t;j++)
{
scanf("%d",&y);
Map[x+1][y+1]=true;
}
}
Count=0;
for(i=1;i<=n;i++)
{
memset(Flag,false,sizeof(Flag));
if(Find(i,n))
Count++;
}
printf("%d\n",n-Count/2);
}
return 0;
}
0 0
- poj 1466 Girls and Boys 最大独立集=n-最小覆盖点
- 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)
- pku(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 && hdu 1068Girls 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(二分图最大独立集)
- Unity 切换Shader耗CPU大
- 法摄影师创意照展现儿童勇战梦中怪兽
- oracle 触发器before和after数据区别
- conversion to dalvik format failed with error 1
- Android WifiDisplay分析三:RTSP交互以及数据传输
- poj 1466 Girls and Boys 最大独立集=n-最小覆盖点
- 最长公共子序列
- hdu2030 汉字统计
- hud 2523 Vote
- Oracle Redo Log Buffer的大小设置
- java类的访问权限解析
- UVa 10608 - Friends
- iOS7 Networking with NSURLSession: Part 1
- ListView的Item不能点击的解决方法