HDU - 1068 Girls and Boys(二分匹配---最大独立集)
题意:给出每个学生的标号及与其有缘分成为情侣的人的标号,求一个最大集合,集合中任意两个人都没有缘分成为情侣。
分析:
1、若两人有缘分,则可以连一条边,本题是求一个最大集合,集合中任意两点都不相连,即最大独立集问题。
2、最大独立集 = 顶点数 - 最大匹配数(匈牙利算法求解)。
3、将一个人拆成两个相同的人进行二分匹配,因此真正的最大匹配数应为得到的最大匹配数/2。
#pragma comment(linker, "/STACK:102400000, 102400000")
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define Min(a, b) ((a < b) ? a : b)
#define Max(a, b) ((a < b) ? b : a)
const double eps = 1e-8;
inline int dcmp(double a, double b){
if(fabs(a - b) < eps) return 0;
return a > b ? 1 : -1;
}
typedef long long LL;
typedef unsigned long long ULL;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
const int MOD = 1e9 + 7;
const double pi = acos(-1.0);
const int MAXN = 1e3 + 10;
const int MAXT = 10000 + 10;
using namespace std;
int a[MAXN][MAXN];
bool used[MAXN];
int vis[MAXN];
int n;
bool dfs(int x){
for(int i = 0; i < n; ++i){
if(a[x][i] && !used[i]){
used[i] = true;
if(vis[i] == -1 || dfs(vis[i])){
vis[i] = x;
return true;
}
}
}
return false;
}
int hungary(){
int ans = 0;
for(int i = 0; i < n; ++i){
memset(used, false, sizeof used);
if(dfs(i)) ++ans;
}
return ans;
}
int main(){
while(scanf("%d", &n) == 1){
memset(a, 0, sizeof a);
memset(vis, -1, sizeof vis);
for(int i = 0; i < n; ++i){
int x, m;
scanf("%d: (%d)", &x, &m);
for(int j = 0; j < m; ++j){
int y;
scanf("%d", &y);
a[x][y] = a[y][x] = 1;
}
}
printf("%d\n", n - hungary() / 2);
}
return 0;
}
HDU - 1068 Girls and Boys(二分匹配---最大独立集)的更多相关文章
- hdu 1068 Girls and Boys (二分匹配)
Girls and Boys Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- (step6.3.2)hdu 1068(Girls and Boys——二分图的最大独立集)
题目大意:第一行输入一个整数n,表示有n个节点.在接下来的n行中,每行的输入数据的格式是: 1: (2) 4 6 :表示编号为1的人认识2个人,他们分别是4.6: 求,最多能找到多少个人,他们互不认识 ...
- 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(匈牙利算法求最大独立集)
Girls and Boys Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU 1068 Girls and Boys(最大独立集合 = 顶点数 - 最大匹配数)
HDU 1068 :题目链接 题意:一些男孩和女孩,给出一些人物关系,然后问能找到最多有多少个人都互不认识. 转换一下:就是大家都不认识的人,即最大独立集合 #include <iostream ...
- hdu 1068 Girls and Boys (最大独立集)
Girls and BoysTime Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- hduoj-----(1068)Girls and Boys(二分匹配)
Girls and Boys Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- hdu1068 Girls and Boys 二分匹配
题目链接: 二分匹配的应用 求最大独立集 最大独立集等于=顶点数-匹配数 本体中由于男孩和女孩的学号是不分开的,所以匹配数应是求得的匹配数/2 代码: #include<iostream> ...
随机推荐
- PAT (Advanced Level) 1128~1131:1128N皇后 1129 模拟推荐系统(set<Node>优化) 1130 中缀表达式
1128 N Queens Puzzle(20 分) 题意:N皇后问题.按列依次给定N个皇后的行号,问N个皇后是否能同时不存在行冲突.列冲突和主副对角线冲突. 分析: 1.根据题意一定不存在列冲突,所 ...
- centos7下yourcompleteme安装
以前装过一回,没成功,现在再来一次 yourcompleteme git https://github.com/ycm-core/YouCompleteMe#installation 检查软件版本 v ...
- 认识json,详解JsonConfig
说到json 初学者很迷茫,不知json怎么为何物,以及怎么用.我简单说下我的了解 既然用了json 我们就要知其然也知其所以然.下面有几个疑问 1.为什么要用json?也就是json 的优势 2.我 ...
- 自己写个tween
public Vector3 begin,end;//起始终止坐标 public float BtoE_time;//用时 float timer,lerp;//计时器和进度值 void Update ...
- 吴裕雄 Bootstrap 前端框架开发——Bootstrap 字体图标(Glyphicons):glyphicon glyphicon-signal
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name ...
- 吴裕雄 Bootstrap 前端框架开发——Bootstrap 字体图标(Glyphicons):glyphicon glyphicon-pencil
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name ...
- JuJu团队12月3号工作汇报
JuJu团队12月3号工作汇报 JuJu Scrum 团队成员 今日工作 剩余任务 困难 于达 修改batch里给sentence加padding的方法 继续调试 无 婷婷 给crossentro ...
- Windows系统批处理命令实现计划关机
操作步骤: 1.新建一个文本文件,粘贴下面代码,保存为shutdown.bat @echo off echo 请输入延迟关机分钟数 echo 小于1分钟将视为立即关机,负数为取消关机 set /p t ...
- 云服务器CentOS7系统环境配置(jdk和tomcat)
配置jdk 下载与安装 如果没有安装wget,首先安装wget工具 yum -y install wget 安装完成后,在网上找到jdk的下载链接,可以在官网找点击此处到官网下载,如果官网下载慢也可以 ...
- EditText监听器------实时监听
前言: 在Android开发中EditText的使用频率还是挺高的,比如登录界面输入密码验证码等,有的时候要求我们要在输入号码后显示是哪家公司的,比如中国移动,中国联通,这是就会用到EditText监 ...