解题报告

http://blog.csdn.net/juncoder/article/details/38160591

题目传送门(POJ)

题目传送门(HDU)

题意:

求满足条件的最大集合:集合内不论什么两个人都没有浪漫关系

思路:

POJ2771一样的题,变的简单多了。POJ2771解题报告

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int n,mmap[550][550],pre[550],vis[550];
int dfs(int x)
{
for(int i=0; i<n; i++) {
if(!vis[i]&&mmap[x][i]) {
vis[i]=1;
if(pre[i]==-1||dfs(pre[i])) {
pre[i]=x;
return 1;
}
}
}
return 0;
}
int main()
{
int i,j,a,b,k;
while(~scanf("%d",&n)) {
memset(mmap,0,sizeof(mmap));
memset(pre,-1,sizeof(pre));
for(i=1; i<=n; i++) {
scanf("%d: (%d) ",&a,&k);
for(j=1; j<=k; j++) {
scanf("%d",&b);
mmap[a][b]=1;
}
}
int ans=0;
for(i=0; i<n; i++) {
memset(vis,0,sizeof(vis));
ans+=dfs(i);
}
printf("%d\n",n-ans/2);
}
return 0;
}
Girls and Boys
Time Limit: 5000MS   Memory Limit: 10000K
Total Submissions: 10348   Accepted: 4608

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.

Output

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

HDU1068/POJ1466_Girls and Boys(二分图/最大独立集=N-最大匹配)的更多相关文章

  1. 【Codevs1922】骑士共存问题(最小割,二分图最大独立集转最大匹配)

    题意: 在一个n*n个方格的国际象棋棋盘上,马(骑士)可以攻击的棋盘方格如图所示.棋盘上某些方格设置了障碍,骑士不得进入. 对于给定的n*n个方格的国际象棋棋盘和障碍标志,计算棋盘上最多可以放置多少个 ...

  2. HDU 1068 Girls and Boys 二分图最大独立集(最大二分匹配)

    Girls and Boys Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  3. HDU 1068 Girls and Boys (二分图最大独立集)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1068 有n个同学,格式ni:(m) n1 n2 n3表示同学ni有缘与n1,n2,n3成为情侣,求集合 ...

  4. hdu - 1068 Girls and Boys (二分图最大独立集+拆点)

    http://acm.hdu.edu.cn/showproblem.php?pid=1068 因为没有指定性别,所以要拆点,把i拆分i和i’ 那么U=V-M (M是最大匹配,U最大独立集,V是顶点数) ...

  5. 长脖子鹿放置【洛谷P5030】二分图最大独立集变形题

    题目背景 众周所知,在西洋棋中,我们有城堡.骑士.皇后.主教和长脖子鹿. 题目描述 如图所示,西洋棋的“长脖子鹿”,类似于中国象棋的马,但按照“目”字攻击,且没有中国象棋“别马腿”的规则.(因为长脖子 ...

  6. Girls and Boys POJ - 1466 【(二分图最大独立集)】

    Problem DescriptionIn the second year of the university somebody started a study on the romantic rel ...

  7. HDU 3829 - Cat VS Dog (二分图最大独立集)

    题意:动物园有n只猫和m条狗,现在有p个小孩,他们有的喜欢猫,有的喜欢狗,其中喜欢猫的一定不喜欢狗,喜欢狗的一定不喜欢猫.现在管理员要从动物园中移除一些动物,如果一个小孩喜欢的动物留了下来而不喜欢的动 ...

  8. HDU3829(KB10-J 二分图最大独立集)

    Cat VS Dog Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others)Total ...

  9. bzoj 1143 二分图最大独立集

    我们可以将一个点拆成两个点x,y,那么如果存在一条i->j的路径,我们就连接xi,yj,那么答案就是n-最大匹配数. 因为i->j所以对于i与j只能选一个,那么我们只需要求出来二分图的最大 ...

随机推荐

  1. 《Head First 设计模式》学习笔记——迭代模式 + 组合模式

    迭代模式设置共生死亡,一般来说.我们只是想实现一个集,我们需要的同时提供这个集合的迭代器,喜欢java中间Collection.List.Set.Map等,这些集合都有自己的迭代器.假如我们要实现一个 ...

  2. VMware vSphere 服务器虚拟化之十八桌面虚拟化之安装View Composer服务器

                        VMware vSphere 服务器虚拟化之十八桌面虚拟化之安装View Composer服务器      View Compose服务可安装在管理虚拟机的vC ...

  3. J2SE习题(2)

    第四.五周练习题 1.a. Define a class called BlogEntry that could be used to store an entry for a  Weblog. Th ...

  4. Linux注意到Makefile

    规则: 目标 : 依靠 命令 make是怎样工作的: (1)make在当前文件夹下寻找makefile或Makefile. (2)假设找到,他会寻找文件里的第一个目标文件(target).并把这个文件 ...

  5. 使用vbs脚本添加域网络共享驱动器

    MapNetworkDrive Method Adds a shared network drive to your computer system. object.MapNetworkDrive(s ...

  6. 玩转html5(三)---智能表单(form),使排版更加方便

    <!DOCTYPE html> <head> <meta http-equiv="Content-Type" content="text/h ...

  7. UIControl-IOS发展

    UIKit提供了一组控件:UISwitch开关.UIButtonbutton.UISegmentedControl分段控件.UISlider滑块.UITextField文本字段控件. UIPageCo ...

  8. HDFS建筑与shell操作

    一个.hadoop1.1.0演示 hadoop它适合于大容量数据存储和分布式计算平台 hadoop核心由hdfs和mapreduce组成 hdfs这是一个主从结构,仅有一个.是namenode:从节点 ...

  9. 在 Swift 语言中更好的处理 JSON 数据:SwiftyJSON

    SwiftyJSON能够让在Swift语言中更加简便处理JSON数据. With SwiftyJSON all you have to do is: ? 1 2 3 4 let json = JSON ...

  10. 【Android进阶】Activity的四种加载模式

    Activity的四种加载模式: 1.standard :系统的默认模式,一次跳转即会生成一个新的实例.假设有一个activity命名为Act1, 执行语句:startActivity(new Int ...