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> ...
随机推荐
- 通过流量管理器和 Azure Functions(作为代理)为全球用户提供最靠近的认知服务(或自定义API)
本实战是一个中等复杂度的综合性实战,涉及到的内容有TrafficManager,AzureFunctions,域名/域名解析等几个内容. 本案例基础介绍: https://www.bilibili.c ...
- MyBatis Generator 下划线转驼峰命名
MyBatis Generator配置文件--指定生成实体类使用实际的表列名作为实体类的属性名 table标签下的设置属性useActualColumnNames用于指定生成实体类时是否使用实际的列名 ...
- 文献阅读报告 - Social BiGAT + Cycle GAN
原文文献 Social BiGAT : Kosaraju V, Sadeghian A, Martín-Martín R, et al. Social-BiGAT: Multimodal Trajec ...
- MS SQLSERVER 自增ID列竟然会重复
MS SQLSERVER 2008 R2 datacenter edition 自增的ID列,设为了主键. 从没遇到过的情况.
- golang 读取 chrome保存的网站账号信息
package main import ( "database/sql" "fmt" "log" "os" " ...
- pwntool基础和ida常用操作
pwntools:http://www.91ri.org/14382.html ida:https://www.jianshu.com/p/d425140c6561
- 使用NlohmannJson写JSON保留插入顺序
1. 正文 nlohmann/json是一个C++的读写JSON的组件,号称使用现代C++范式写的.简单看了一下,这个组件确实包含了很多cpp11以上的特性,在vs2015及一下的版本甚至没办法正常编 ...
- 十四、 React路由(react-router4.x): 动态路由、get传值、React中使用url模块
概述 新闻列表 -跳转-> 详情页 时,想把列表对应的id传到详情页里,可用到三种传值方法: 1.动态路由传值 2.get传值 3.localstorage传值 一.动态路由传值 [App.js ...
- 吴裕雄 Bootstrap 前端框架开发——Bootstrap 字体图标(Glyphicons):glyphicon glyphicon-align-justify
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name ...
- ELK 安装Elasticsearch
章节 ELK 介绍 ELK 安装Elasticsearch ELK 安装Kibana ELK 安装Beat ELK 安装Logstash ELK栈要安装以下开源组件: Elasticsearch Ki ...