HDU1068/POJ1466_Girls and Boys(二分图/最大独立集=N-最大匹配)
解题报告
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;
}
Time Limit: 5000MS | Memory Limit: 10000K | |
Total Submissions: 10348 | Accepted: 4608 |
Description
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 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
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-最大匹配)的更多相关文章
- 【Codevs1922】骑士共存问题(最小割,二分图最大独立集转最大匹配)
题意: 在一个n*n个方格的国际象棋棋盘上,马(骑士)可以攻击的棋盘方格如图所示.棋盘上某些方格设置了障碍,骑士不得进入. 对于给定的n*n个方格的国际象棋棋盘和障碍标志,计算棋盘上最多可以放置多少个 ...
- HDU 1068 Girls and Boys 二分图最大独立集(最大二分匹配)
Girls and Boys Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU 1068 Girls and Boys (二分图最大独立集)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1068 有n个同学,格式ni:(m) n1 n2 n3表示同学ni有缘与n1,n2,n3成为情侣,求集合 ...
- hdu - 1068 Girls and Boys (二分图最大独立集+拆点)
http://acm.hdu.edu.cn/showproblem.php?pid=1068 因为没有指定性别,所以要拆点,把i拆分i和i’ 那么U=V-M (M是最大匹配,U最大独立集,V是顶点数) ...
- 长脖子鹿放置【洛谷P5030】二分图最大独立集变形题
题目背景 众周所知,在西洋棋中,我们有城堡.骑士.皇后.主教和长脖子鹿. 题目描述 如图所示,西洋棋的“长脖子鹿”,类似于中国象棋的马,但按照“目”字攻击,且没有中国象棋“别马腿”的规则.(因为长脖子 ...
- Girls and Boys POJ - 1466 【(二分图最大独立集)】
Problem DescriptionIn the second year of the university somebody started a study on the romantic rel ...
- HDU 3829 - Cat VS Dog (二分图最大独立集)
题意:动物园有n只猫和m条狗,现在有p个小孩,他们有的喜欢猫,有的喜欢狗,其中喜欢猫的一定不喜欢狗,喜欢狗的一定不喜欢猫.现在管理员要从动物园中移除一些动物,如果一个小孩喜欢的动物留了下来而不喜欢的动 ...
- HDU3829(KB10-J 二分图最大独立集)
Cat VS Dog Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others)Total ...
- bzoj 1143 二分图最大独立集
我们可以将一个点拆成两个点x,y,那么如果存在一条i->j的路径,我们就连接xi,yj,那么答案就是n-最大匹配数. 因为i->j所以对于i与j只能选一个,那么我们只需要求出来二分图的最大 ...
随机推荐
- Test SRM Level One: TemperatureScales
题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=6038 因为TopCoder SRM比赛使用的编译器进行了升级, ...
- JAVA编程思想(2) - 操作符(一)
"在最底层,Java中的数据是通过操作符来操作的." 1. 使用Java操作符 -操作符接受一个或者多个參数,并生成一个新值,參数的形式与普通的方法调用不用,但效果是同样的.加号和 ...
- Canvas翻转方法
// 普通抽奖: // ctx.drawImage(img, px, py); // 级别"翻转"帆布 ctx.translate(canvas_width, 0); ctx. ...
- JavaEE SSH集成框架(两) struts2 本地加载dtd文件,action组态
1. 载入中struts2的dtd文件.使struts.xml网络无法验证,和eclipse有技巧 在src在创建struts.xml: <? xmlversion="1.0" ...
- ZOJ 3826 Hierarchical Notation 模拟
模拟: 语法的分析 hash一切Key建设规划,对于记录在几个地点的每个节点原始的字符串开始输出. . .. 对每一个询问沿图走就能够了. .. . Hierarchical Notation Tim ...
- earlysuspend调用过程
1. 电源管理的状态 Android的Linux内核为系统提供了4种电源状态,内核的源码为当中的3种定义了名字和相应的宏定义,名字定义在kernel/power/suspend.c中: constch ...
- Android新建项目后src下没有自动生成文件
最近开始学Android了,按照教材新建了一个项目,发现src下没有自动生成文件,怎么回事呢? 出现这种可能的原因很可能是ADT与SDK版本不同,造成不兼容. 在ADT(或者eclipse)中的hel ...
- HDU 2017 一系列统计数据
一系列统计数据 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Su ...
- C日常语言实践中小(四)——勇者斗恶龙
勇者斗恶龙 愿你的国有n龙的头,你想聘请骑士杀死它(全部的头). 村里有m个骑士能够雇佣,一个能力值为x的骑士能够砍掉恶龙一个致敬不超过x的头,且须要支付x个金币. 怎样雇佣骑士才干砍掉恶龙的全部头, ...
- C++基于该模型模板包括节目外实例
一个."经典模式"失败 我们学过C++的人都知道.在C++中组织代码的经典模型是:将函数或类的声明和定义部分分开在不同的文件之中 , 即一般将声明放在一个.h的头文件里而定义在 ...