Girls and Boys

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

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
 
 

题意大致为: 有一个学校,男生女生要搭配,然后排除男神和男生搞基,女生和女生玩拉拉的意思,问最少有多少个落单的倒霉求?

 
其实就是变相的,最大匹配,就是求出了最大匹配,然后剩下的那些个倒霉求就是所求的答案嘛.....
 
 
代码:
 #include<cstring>
#include<cstdio>
#include<cstdlib>
using namespace std;
const int maxn=;
int n,a,b,c;
bool mat[maxn][maxn];
bool vis[maxn];
int girl[maxn];
bool check(int x){
for(int i=;i<n;i++){
if(mat[x][i]==&&!vis[i]){
vis[i]=;
if(girl[i]==-||check(girl[i])){
girl[i]=x;
return ;
}
}
}
return ;
}
int main()
{
//freopen("test.in","r",stdin);
while(scanf("%d",&n)!=EOF){
memset(mat,,sizeof(mat));
memset(girl,-,sizeof(girl));
for(int i=;i<n;i++){
scanf("%d: (%d)",&a,&b);
while(b--){
scanf("%d",&c);
mat[a][c]=;
}
}
int ans=;
for(int j=;j<n;j++){
memset(vis,,sizeof(vis));
if(check(j))ans++;
}
/*通过最大二分匹配,我们得到了最大匹配数,但是由于男生女生
都算了一遍,所以是不是就得除以二。这样就是最大匹配数了*/
printf("%d\n",n-ans/);
}
return ;
}
 

最新文章

  1. ajax的post方式和get方式比较,以及需要注意的地方
  2. php翻页
  3. js的动态加载、缓存、更新以及复用(一)
  4. 学期总结ngu
  5. android webview删除缓存
  6. acdream 1685 多民族王国(DFS,并查集)
  7. How to get cocoapods work on Yosemite
  8. Matlab实现ItemBasedCF算法
  9. 【C语言】37个关键字
  10. Android 的 Relative Layout 常量
  11. cocos2dx进阶学习之CCLayer
  12. HSQLDB相关信息及用法汇总
  13. 基于Kafka Connect框架DataPipeline在实时数据集成上做了哪些提升?
  14. php禁止某ip或ip地址段访问的方法(转载)
  15. 子级div相对于父级div位置不变
  16. Confluence 6 查看所有空间
  17. requestAnimationFrame结束demo
  18. 860. Lemonade Change
  19. POJ 2845
  20. thymeleaf-extras-shiro

热门文章

  1. JavaWeb(一)
  2. 梯度下降法VS随机梯度下降法 (Python的实现)
  3. 多线程技术在iOS开发中的使用
  4. 自定义CSS博客(转)
  5. CSS笔记(一)CSS规则
  6. iOS - Swift NSProcessInfo 系统进程信息
  7. iOS - UIKit
  8. Git与Repo入门(转载)
  9. 了解OpenStack
  10. iOS开发之用Xcode 在真机上截屏与模拟器截屏