HDU——T 1068 Girls and Boys

http://acm.hdu.edu.cn/showproblem.php?pid=1068

Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 12257    Accepted Submission(s): 5775


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.
 

 

Sample Input
7 0: (3) 4 5 6 1: (2) 4 6 2: (0) 3: (0) 4: (2) 0 1 5: (1) 0 6: (2) 0 1 3 0: (2) 1 2 1: (1) 0 2: (1) 0
 

 

Sample Output
5 2
 

 

Source
 

 

Recommend
JGShining   |   We have carefully selected several similar problems for you:   1150  1151  1281  1507  1528 
 
 
(男女没有关系)最大独立子集=总点数-最大匹配数
因为男女人数不是分开的,所以在同一集合,最大匹配数/=2;
 1 #include <cstring>
 2 #include <cstdio>
 3 
 4 using namespace std;
 5 
 6 const int N(2333);
 7 int n,match[N];
 8 bool map[N][N],vis[N];
 9 
10 bool find(int u)
11 {
12     for(int v=0;v<n;v++)
13     if(map[u][v]&&!vis[v])
14     {
15         vis[v]=1;
16         if(!match[v]||find(match[v]))
17         {
18             match[v]=u;
19             return true;
20         }
21     }
22     return false;
23 }
24 
25 inline void read(int &x)
26 {
27     x=0; register char ch=getchar();
28     for(;ch>'9'||ch<'0';) ch=getchar();
29     for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
30 }
31 
32 int AC()
33 {
34     for(int ans=0;~scanf("%d",&n);ans=0)
35     {
36         for(int v,u,q,i=0;i<n;i++)
37         {
38             read(u);
39             for(read(q);q--;)
40                 read(v),map[u][v]=1;
41         }
42         for(int i=0;i<n;i++)
43         {
44             if(find(i)) ans++;
45             memset(vis,0,sizeof(vis));
46         }
47         printf("%d\n",n-ans/2);
48         memset(map,0,sizeof(map));
49         memset(match,0,sizeof(match));
50     }
51     return 0;
52 }
53 
54 int I_want_AC=AC();
55 int main(){;}

 

转载于:https://www.cnblogs.com/Shy-key/p/7425076.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值