(step6.3.2)hdu 1068(Girls and Boys——二分图的最大独立集)
题目大意:第一行输入一个整数n,表示有n个节点。在接下来的n行中,每行的输入数据的格式是:
1: (2) 4 6 :表示编号为1的人认识2个人,他们分别是4、6;
求,最多能找到多少个人,他们互不认识
解题思路:二分图的最大独立集。
1)最大独立集 = 节点数 - 最大匹配数/2;
2)令女生数= 男生数 = 总数
3) 1: (2)可以采用scanf("%d: (%d)",&a,&b);来输入
代码如下:
/*
* 1068_1.cpp
*
* Created on: 2013年8月30日
* Author: Administrator
*/
#include <iostream> using namespace std; const int maxn = 1001;
int map[maxn][maxn];
int link[maxn];
bool useif[maxn];
int n; int can(int t){
int i;
for(i = 0 ; i < n ; ++i){
if(useif[i] == 0 && map[t][i]){
useif[i] = 1;
if(link[i] == -1 || can(link[i])){
link[i] = t;
return 1;
}
}
}
return 0;
} int max_match(){
int i;
int num = 0;
memset(link,-1,sizeof(link));
for(i = 0 ; i < n; ++i){
memset(useif,0,sizeof(useif));
if(can(i)){
num++;
}
}
return num;
} int main(){
while(scanf("%d",&n)!=EOF){
int i,j;
memset(map,0,sizeof(map));
for(i = 0 ; i < n ; ++i){
int a,b;
scanf("%d: (%d)",&a,&b);
for(j = 0 ; j < b ; ++j){
int c;
scanf("%d",&c);
map[a][c] = 1;
}
} printf("%d\n",n - max_match()/2);
}
}
(step6.3.2)hdu 1068(Girls and Boys——二分图的最大独立集)的更多相关文章
- 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 二分图最大独立集(最大二分匹配)
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 本题求二分图最大独立点集.因为最大独立点集=顶点数-最大匹配数.所以转化为求最大匹配.因为没有给 ...
- hdu 1068 Girls and Boys 二分图的最大匹配
题目链接:pid=1068">http://acm.hdu.edu.cn/showproblem.php? pid=1068 #include <iostream> #in ...
- hdu - 1068 Girls and Boys (二分图最大独立集+拆点)
http://acm.hdu.edu.cn/showproblem.php?pid=1068 因为没有指定性别,所以要拆点,把i拆分i和i’ 那么U=V-M (M是最大匹配,U最大独立集,V是顶点数) ...
- HDU 1068 Girls And Boys 二分图题解
版权声明:本文作者靖心.靖空间地址:http://blog.csdn.net/kenden23/,未经本作者同意不得转载. https://blog.csdn.net/kenden23/article ...
- HDU - 1068 Girls and Boys(二分匹配---最大独立集)
题意:给出每个学生的标号及与其有缘分成为情侣的人的标号,求一个最大集合,集合中任意两个人都没有缘分成为情侣. 分析: 1.若两人有缘分,则可以连一条边,本题是求一个最大集合,集合中任意两点都不相连,即 ...
- HDU 1068 Girls and Boys(最大独立集合 = 顶点数 - 最大匹配数)
HDU 1068 :题目链接 题意:一些男孩和女孩,给出一些人物关系,然后问能找到最多有多少个人都互不认识. 转换一下:就是大家都不认识的人,即最大独立集合 #include <iostream ...
- hdu 1068 Girls and Boys (二分匹配)
Girls and Boys Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
随机推荐
- SQL基础使用
result = executeQuery(“ SELECT FName, FSalary FROM T_Employee ”); for(i=0;i<result.count;i++) { s ...
- Triangle---minimum path sum
动态规划 class Solution: # @param triangle, a list of lists of integers # @return an integer def minimum ...
- BZOJ 1901: Zju2112 Dynamic Rankings( BIT 套 BST )
BIT 套 splay 其实也是不难...每个 BIT 的结点保存一颗 splay , 询问就二分答案然后判断rank... ------------------------------------- ...
- 11-UIKit(Storyboard、View的基本概念、绘制图形、UIBezierPath)
目录: 1. Storyboard 2. Views 3. View的基本概念介绍 4. 绘制图形 5. UIBezierPath 回到顶部 1. Storyboard 1.1 静态表视图 1)Sec ...
- pytesser图片文本识别
python图片文本识别使用的工具是PIL和pytesser.因为他们使用到很多的python库文件,为了避免一个个工具的安装,建议使用pythonxy,这个工具的介绍可参考baidu. pytess ...
- android 调用系统打电话和发短,懒得记
Intent intent = new Intent(); intent.setAction(Intent.ACTION_CALL); intent.setData( ...
- HDU-1664-Different Digits(BFS)
Problem Description Given a positive integer n, your task is to find a positive integer m, which is ...
- Win8.1应用开发之动态磁贴
using demo02.Common; using System; using System.Collections.Generic; using System.IO; using System.L ...
- Ch04 充满动作的控制器
4.1 考察控制器和动作 4.1.1 IController与控制器基类 4.1.2 如何形成动作方法 4.2 哪些应该放在动作方法中 4.2.1 手动映射视图模型 4.2.2 输入验证 ...
- QWidget类中默认是忽略inputMethodEvent事件(要获取输入的内容就必须使用这个事件)
因为项目的需要以及主管的要求,准备将工程移植到Qt中,这样就可以比较容易的实现跨平台了.因为之前工程是在windows下开发的,第一个平台又是mobile所以除了底层框架之外其他的都是使用的windo ...