题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1068

思路:

求一集合满足,两两之间没有恋爱关系

思路:

最大独立点集=顶点数-最大匹配数

这里给出的关系,看似有向边,实则是无向边,那么按照二分匹配处理的话,相当于一个人看作两个人来用,最后还是顶点数目-最大二分匹配数

因为之间一个人当作两个人用,二分匹配数目减半,即 = n - match()/2

或者也可以写成 = ( 2n -  match() )/2 更容易理解

题目中n的大小没有说明,最好开大一点,最后测得的大小在500以内

代码:

 #include <stdio.h>
#include <string.h>
const int maxn=;
int n;
int g[maxn][maxn],vis[maxn],who[maxn];
bool F(int x) {
for(int i=; i<n; ++i) {
if(g[x][i]&&!vis[i]) {
vis[i]=;
if(who[i]==-||F(who[i])) {
who[i]=x;
return true;
}
}
}
return false;
}
int main() {
while(~scanf("%d",&n)) {
memset(g,,sizeof(g));
memset(who,-,sizeof(who));
int temp=n,u,v,num;
while(temp--) {
scanf("%d: (%d)",&u,&num);
while(num--) {
scanf("%d",&v);
g[u][v]=g[v][u]=;
}
}
int sum=;
for(int i=; i<n; ++i) {
memset(vis,,sizeof(vis));
if(F(i)) sum++;
}
printf("%d\n",n-sum/);
}
return ;
}

hdu 1068 Girls and Boys 最大独立点集 二分匹配的更多相关文章

  1. [HDU] 1068 Girls and Boys(二分图最大匹配)

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1068 本题求二分图最大独立点集.因为最大独立点集=顶点数-最大匹配数.所以转化为求最大匹配.因为没有给 ...

  2. POJ Girls and Boys (最大独立点集)

                                                                Girls and Boys Time Limit: 5000MS   Memo ...

  3. HDU 1068 Girls and Boys(最大独立集合 = 顶点数 - 最大匹配数)

    HDU 1068 :题目链接 题意:一些男孩和女孩,给出一些人物关系,然后问能找到最多有多少个人都互不认识. 转换一下:就是大家都不认识的人,即最大独立集合 #include <iostream ...

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

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

  5. hdu 1068 Girls and Boys (二分匹配)

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

  6. hdu 1068 Girls and Boys(匈牙利算法求最大独立集)

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

  7. HDU——1068 Girls and Boys

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

  8. hdu 1068 Girls and Boys (最大独立集)

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

  9. HDU 1068 Girls and Boys(模板——二分图最大匹配)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1068 Problem Description the second year of the univ ...

随机推荐

  1. *.do和*.action的区别

    最近发现个问题,都是SpringMVC 请求地址有的是*.do有的是*.action,想了半天区别没想出来. struts早期的1版本,以.do为后缀.同时spring的MVC也是以.do为后缀.几年 ...

  2. LeetCode 283. Move Zeroes (移动零)

    Given an array nums, write a function to move all 0's to the end of it while maintaining the relativ ...

  3. Python 读取某个目录下的文件

    读取某个目录下的文件,如'/Users/test/test_kmls'目录下有test1.txt.test2.txt. 第一种方法读出的all_files是test1.txt.test2.txt im ...

  4. 还原NuGet程序包

    官网:https://msdn.microsoft.com/zh-cn/magazine/hh547106.aspx 在获取团队中的项目或者下载他人的项目Demo后,运行项目有时会提示某些dll找不到 ...

  5. 算法:JavaScript两数之和

    题目 Given an array of integers, return indices of the two numbers such that they add up to a specific ...

  6. [J2EE] 有关 PreparedStatement

    今天同事遇到一个问题,简言之,就是PreparedStatement的预编译究竟是怎么发挥作用的... 嘿嘿,说来惭愧,我以前就只知道PreparedStatement比Statement要好,要防S ...

  7. Python把给定的列表转化成二叉树

    在LeetCode上做题时,有很多二叉树相关题目的测试数据是用列表给出的,提交的时候有时会出现一些数据通不过,这就需要在本地调试,因此需要使用列表来构建二叉树,方便自己调试.LeetCode上二叉树结 ...

  8. 应用在安卓和ios端APP的证件识别

    移动端证件识别智能图文处理,是利用OCR识别技术,通过手机拍摄身份证图像或者从手机相册中加载证件图像,过滤身份证的背景底纹干扰,自动分析证件各文字进行字符切分.识别,最后将识别结果按姓名.地址.民族. ...

  9. mac下selenium+python环境搭建

    selenium2+python的环境搭建主要需要python和selenium 1.python mac下自带了python,可以查看版本.当然可以选择安装其它版本的python. 2.seleni ...

  10. 前端框架:react还是vue?

    之前写了一篇前端框架的大汇总,主要介绍了当下主流的框架和其特性.最近除了bootstrap,就属react和vue最为热门,这篇就主要拿这两个框架来做一下详细对比. 究竟如何正确使用?作为小白的我们从 ...