解题报告

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. BackTrack5 (BT5)无线password破解教程WPA/WPA2-PSK无线password皴

    昨天公布了BackTrack5 (BT5)无线weppassword破解教程之minidwep-gtk破解法一文,对BT5下破解wep无线password的简单方法做了介绍,今天奶牛为朋友们介绍下怎样 ...

  2. Atitit.列表页and查询条件的最佳实践(1)------设定搜索条件and提交查询and返回json数据

    Atitit.列表页and查询条件的最佳实践(1)------设置查询条件and提交查询and返回json数据 1. 1. 配置条件字段@Conditional 1 1 2. 2. 配置条件字段显示类 ...

  3. Android - match_parent 和 fill_parent差异

    Android - match_parent 和 fill_parent差异 本文地址: http://blog.csdn.net/caroline_wendy match_parent 和 fill ...

  4. Directx11学习笔记【七】 游戏定时器的实现

    无论是在动画还是在一些游戏中,定时器总是必不可少的,游戏的帧数动画的播放等都离不开定时器的控制.这里以dx11龙书中提供的定时器为例,具体看看是怎么实现一个简单但精度高使用方便的定时器的. 这个定时器 ...

  5. WebAPI 15 CORS

    WebAPI 15 CORS 同源策略 首先基于安全的原因,浏览器是存在同源策略这个机制的,同源策略阻止从一个源加载的文档或脚本获取或设置另一个源加载的文档的属性. 对于同源必须要求URL在如下几个方 ...

  6. 【Android基础】单元测试的配置

    1.在AndroidManifest清单文件中进行配置 <application android:allowBackup="true" android:debuggable= ...

  7. docker 真实---安装基本映像 (一)

    浸泡了几天的官方网站,正确docker有了更好的理解.准备着手建立一个公司的开发和测试环境,包含java.python. 环境介绍 首先说明一下我的环境 2物理server(以后简称为主机) 主机A配 ...

  8. 初步STL集装箱Vector

    vector 特点: 1.可变长的动态数组 2.使用时包括头文件 #include <vector> 3.支持随机訪问迭代器 • 依据下标随机訪问某个元素时间为常数 • 在尾部加入速度非常 ...

  9. 学习json-rpc

    最近做一个和SmartHome相关的项目,文档不全不说,连个像样的Demo都没,痛苦!!当然,这是题外话.今天来说说项目中主要用到的通讯协议:json-rpc,简单地说,它是以json格式进行的远程调 ...

  10. MEF初体验之八:过滤目录

    当在使用子容器的时候,基于某些具体标准来过滤目录可能是重要的.例如,基于部件的创建策略来过滤是很常见的.下面的代码片段演示了如何构建这种特别方法: var catalog = new Assembly ...