hdu1068 Girls and Boys --- 最大独立集
有一个集合男和一个集合女,给出两集合间一些一一相应关系。问该两集合中的最大独立集的点数。
最大独立集=顶点总数-最大匹配数
此题中。若(a,b)有关。则(b,a)有关。每个关系算了两次,相当于二分图的两边集合没有分男女。两边都是总人数。
所以此题中答案应该是 顶点总数-最大匹配数/2
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
const int maxn=510;
using namespace std; int mx[maxn],my[maxn],vis[maxn],e[maxn][maxn],n; int path(int i)
{
int j;
for(j=0;j<n;j++)
{
if(e[i][j]&&!vis[j])
{
vis[j]=1;
if(my[j]==-1||path(my[j]))
{
my[j]=i;
mx[i]=j;
return 1;
}
}
}
return 0;
} int hungry()
{
int res=0;
memset(mx,-1,sizeof mx);
memset(my,-1,sizeof my);
for(int i=0;i<n;i++)
{
if(mx[i]==-1)
{
memset(vis,0,sizeof vis);
res+=path(i);
}
}
return res;
} int main()
{
int a,b,m,i;
while(~scanf("%d",&n))
{
memset(e,0,sizeof e);
for(i=0;i<n;i++)
{
scanf("%d: (%d)",&a,&m);
while(m--)
{
scanf("%d",&b);
e[a][b]=1;
}
}
printf("%d\n",n-hungry()/2);
}
return 0;
}
hdu1068 Girls and Boys --- 最大独立集的更多相关文章
- hdu 1068 Girls and Boys (最大独立集)
Girls and BoysTime Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- hdu1068 Girls and Boys
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1068 二分图的最大独立集数=节点数(n)— 最大匹配数(m) 另外需要注意的是: 本题求出的最大匹配数是实 ...
- HDU 1068 Girls and Boys(最大独立集合 = 顶点数 - 最大匹配数)
HDU 1068 :题目链接 题意:一些男孩和女孩,给出一些人物关系,然后问能找到最多有多少个人都互不认识. 转换一下:就是大家都不认识的人,即最大独立集合 #include <iostream ...
- hdu1068 Girls and Boys 二分匹配
题目链接: 二分匹配的应用 求最大独立集 最大独立集等于=顶点数-匹配数 本体中由于男孩和女孩的学号是不分开的,所以匹配数应是求得的匹配数/2 代码: #include<iostream> ...
- hdu1068 Girls and Boys 匈牙利算法(邻接表)
#include <cstdio> #include <algorithm> #include <cstring> #include <vector> ...
- hdu1068 Girls and Boys 基础匈牙利
#include <cstdio> #include <cstring> #include <algorithm> #include <cstdlib> ...
- HDU 1068 Girls and Boys 二分图最大独立集(最大二分匹配)
Girls and Boys Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- poj 1466 Girls and Boys(二分图的最大独立集)
http://poj.org/problem?id=1466 Girls and Boys Time Limit: 5000MS Memory Limit: 10000K Total Submis ...
- hdoj 1068 Girls and Boys【匈牙利算法+最大独立集】
Girls and Boys Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
随机推荐
- 小HY的四元组
4.7 比赛T1,然而这题爆零了 其实很简单的...其实哈希都不用 所以首先记录每组的差值,按其sort一下再暴力找即可 #include<cstdio> #include<iost ...
- $CF1141B Maximal Continuous Rest$
告诉你一天n件事情 a[i]为1是休息 a[i]为2是工作 求最长连续的休息时间(即最长的1 可以作为环状来求.(即环状最长的1 这题就可以用前缀和贪心等什么操作.. 然后用\(ans1ans2\)瞎 ...
- python--修改默认递归层级
import sys sys.setrecursionlimit(最大递归次数)
- 【转】Linux命令学习手册-split命令
转自:http://blog.chinaunix.net/uid-9525959-id-3054325.html split [OPTION] [INPUT [PREFIX]] [功能]将文件分割成多 ...
- Android生命周期回顾
先回顾生命周期 Activity一共有3中状态 运行中 Activity位于前台,并具有用户焦点 暂停 另一个Activity位于屏幕前台并具有用户焦点,但此Activity仍可见.也就是说,另一个A ...
- Java_Web三大框架之Hibernate+HQL语言基础
12.1 HQL语言基础Hibernate查询语言为HQL(Hibernate Query Language),可以直接使用实体类名及属性.HQL语法类似于SQL,有SQL的关键词如select.fr ...
- struts.xml详解
参考自:http://blog.csdn.net/zz_mm/article/details/5460397 1. 深入Struts2的配置文件 本部分主要介绍struts.xml的常用配置. ...
- Java多线程学习笔记(三)——Future和FutureTask
Future接口:它是对于具体的Runnable或者Callable任务的执行结果进行取消.查询是否完成.获取结果.必要时可以通过get方法获取执行结果,该方法会阻塞直到任务返回结果. 接口中有5中方 ...
- js 不能用关键字 delete 做函数名
把delete更改为mydelete正常.
- 批量obj格式直接转gltf
在cesium中的模型需要的是gltf或glb格式的文件,之前的做法是用将模型从3d max中导出dae格式的文件(需要插件),然后用collada2gltf工具将dae格式转成gltf. 最近翻看c ...