题目大意:第一行输入一个整数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——二分图的最大独立集)相关推荐

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

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

  2. 【HDOJ】1068 Girls and Boys

    匈牙利算法,最开始暴力解不知道为什么就是wa,后来明白,一定要求最优解.查了一下匈牙利算法相关内容,大致了解. 1 #include <stdio.h> 2 #include <st ...

  3. Girls and Boys

    http://acm.hdu.edu.cn/showproblem.php?pid=1068 题意:在大学校园里男女学生存在某种关系,现在给出学生人数n,并给出每个学生与哪些学生存在关系(存在关系的学 ...

  4. Girls and Boys||HDU1068

    link:http://acm.hdu.edu.cn/showproblem.php?pid=1068 Problem Description the second year of the unive ...

  5. hdu 1068(二分图最大独立集)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1068 解题思路: 这题大概意思就是说找出一个最大的集合使得该集合的任意两个人木有关系. 根据最大独立集 ...

  6. poj 1466 Girls and Boys (最大独立集)

    http://poj.org/problem?id=1466 题意:一些 boys 和girls  有暧昧关系,我们要选出 一些人,这些人 任意两个人之间没有暧昧 关系,求最多可以选出 多少人. 题解 ...

  7. HDU-1068 Girls and Boys

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1068 the second year of the university somebody start ...

  8. TZOJ 1321 Girls and Boys(匈牙利最大独立集)

    描述 the second year of the university somebody started a study on the romantic relations between the ...

  9. hdu1068 Girls and Boys --- 最大独立集

    有一个集合男和一个集合女,给出两集合间一些一一相应关系.问该两集合中的最大独立集的点数. 最大独立集=顶点总数-最大匹配数 此题中.若(a,b)有关.则(b,a)有关.每个关系算了两次,相当于二分图的 ...

最新文章

  1. ecos 编译时无法找到 tclConfig.sh 和 tkConfig.sh
  2. SUBSTRING函數用法
  3. 欧洲、加拿大、澳大利亚新增2.1万个点可购买比特币现金
  4. linux /proc目录文件详解
  5. leetcode刷题练习
  6. 数值计算方法在计算机的应用,数值计算方法在计算机科学中的应用和误差序列实验推荐.doc...
  7. POJ 2312 Battle City 优先队列+BFS
  8. 华为辞职门事件——再谈工作问题
  9. 登录微信用android设备,Android 之微信登录
  10. 阿里技术:如何画出一张合格的技术架构图?
  11. html 比 htm 的载入速度快,htm和html
  12. HBase之MVCC
  13. linux配置iscsi无账号密码,linux4 如何配置iscsi启动器
  14. docker 镜像 增删改查
  15. AspectJ 在 Spring 中的使用
  16. Easeljs之regX/regY详解
  17. linux 下tomcat开机自启动
  18. OpenGL编程指南(红宝书)第九版使用指南
  19. 小程序js车牌号手机号正则表达
  20. esxi install DS3615XS

热门文章

  1. vs2010 asp.net mysql,安装VS2010后,更改iis的asp.net版本 | 吴小强的博客
  2. java ef 引用问题_java调用shell(ps -ef | grep )问题
  3. c语言编写动画屏保源码,发个C代码(简单动画演示)
  4. 计算方位角_全站仪各方面应用的原理、操作及计算,看这篇就对了!
  5. php遍历中记录所有,php遍历类中包含的所有元素的方法
  6. MyObjectUtil对象工具类
  7. 3台廉价机器每秒写入2百万!Kafka为什么那么快?
  8. Vue组件之全局组件与局部组件
  9. 《剑指offer》和为s的连续正数序列
  10. scala中使用Option、Some、None,避免使用null