解题报告

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. svn 使用(一个)

    一个. 安装svn  server(操作系统centos) yum install subversion 通过 subversion -v 如果成功安装命令来查看 温馨提示不承担任何subversio ...

  2. 重新想象 Windows 8 Store Apps (11) - 控件之 ListView 和 GridView

    原文:重新想象 Windows 8 Store Apps (11) - 控件之 ListView 和 GridView [源码下载] 重新想象 Windows 8 Store Apps (11) - ...

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

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

  4. Linux高性能server规划——多进程编程

    多进程编程 多进程编程包含例如以下内容: 复制进程影映像的fork系统调用和替换进程映像的exec系列系统调用. 僵尸进程以及怎样避免僵尸进程 进程间通信(Inter-Process Communic ...

  5. Android开发框架SmartAndroid2.0 强劲框架

    SmartAndroid 是一个功能强劲的 Android 框架,作为一个简单而"优雅"的工具库包,它能够为 Android 开发人员建立功能完好的Android 应用程序. 经过 ...

  6. Case learning

    bad case: <?php foreach($user_detail AS $val) { if(!empty($val->portrait)) { //假设这个循环从来没有到达过 $ ...

  7. Ubuntu通过使用PyCharm 执行调试 Odoo 8.0 可能的问题

    实现步骤,请移步http://shine-it.net/index.php?topic=16603.0 或 http://www.mindissoftware.com/2014/09/11/Run-O ...

  8. MSSQL连接字符串,你真的清楚吗?

    原文:MSSQL连接字符串,你真的清楚吗? 几年前当我第一次面试时,考官发现我是个新手于是他让我写个连接字符串,虽然当时就知道X种连接字符串的写法,但是当时却没能写对一个,工作多年后我仍然不能写一个正 ...

  9. NET中小型企业项目开发框架系列(一个)

    当时的前端,我们开发了基于Net一组结构sprint.NET+NHibernate+MVC+WCF+EasyUI等中小型企业级系统开发平台,如今把整个开发过程中的步步进展整理出来和大家分享,这个系列可 ...

  10. Java他们其中一个IO(一)

    1.I/O 操作的目标 其中从数据源读取数据,和写数据到的目标位置数据. 2.IO 的分类方法 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMTc ...