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

题目大意:

给你各个人可以属于的组,把这些人分组,使这些组中人数最多的组人数最少,并输出这个人数。
解题思路:

一组可以有多人,一人只能分到一组,显然是多重匹配,只要枚举一下每组的限制人数limit,用多重匹配判断即可。

代码

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
const int N=1e3+;
const int M=5e2+; int n,m,limit;
int link[M][N];
bool vis[M];
vector<int>v[N]; bool dfs(int u){
for(int i=;i<v[u].size();i++){
int t=v[u][i];
if(vis[t]) continue;
vis[t]=true;
if(link[t][]<limit){
link[t][++link[t][]]=u;
return true;
}
for(int i=;i<=limit;i++){
if(dfs(link[t][i])){
link[t][i]=u;
return true;
}
}
}
return false;
}
//多重匹配
bool mul_match(){
for(int i=;i<=m;i++) link[i][]=;
for(int i=;i<n;i++){
memset(vis,false,sizeof(vis));
if(!dfs(i)) return false;
}
return true;
} int main(){
while(~scanf("%d%d",&n,&m)&&n&&m){
for(int i=;i<=n;i++) v[i].clear();
char op[];
for(int i=;i<n;i++){
scanf("%s",op);
int x;
while(getchar()==' '){
scanf("%d",&x);
v[i].push_back(x);
}
}
//二分枚举上限人数
int l=,r=1e3,ans=;
while(l<=r){
limit=(l+r)/;
if(mul_match()){
r=limit-;
ans=limit;
}
else l=limit+;
}
printf("%d\n",ans);
}
return ;
}

HDU 1669 Jamie's Contact Groups(多重匹配+二分枚举)的更多相关文章

  1. POJ 2289 Jamie's Contact Groups / UVA 1345 Jamie's Contact Groups / ZOJ 2399 Jamie's Contact Groups / HDU 1699 Jamie's Contact Groups / SCU 1996 Jamie's Contact Groups (二分,二分图匹配)

    POJ 2289 Jamie's Contact Groups / UVA 1345 Jamie's Contact Groups / ZOJ 2399 Jamie's Contact Groups ...

  2. 【HDOJ】1669 Jamie's Contact Groups

    二分+二分图多重匹配. /* 1669 */ #include <iostream> #include <string> #include <map> #inclu ...

  3. POJ 2112 Optimal Milking(Floyd+多重匹配+二分枚举)

    题意:有K台挤奶机,C头奶牛,每个挤奶机每天只能为M头奶牛服务,下面给的K+C的矩阵,是形容相互之间的距离,求出来走最远的那头奶牛要走多远   输入数据: 第一行三个数 K, C, M  接下来是   ...

  4. POJ2289 Jamie's Contact Groups(二分图多重匹配)

    Jamie's Contact Groups Time Limit: 7000MS   Memory Limit: 65536K Total Submissions: 7721   Accepted: ...

  5. poj 2289 Jamie's Contact Groups【二分+最大流】【二分图多重匹配问题】

    题目链接:http://poj.org/problem?id=2289 Jamie's Contact Groups Time Limit: 7000MS   Memory Limit: 65536K ...

  6. POJ2289:Jamie's Contact Groups(二分+二分图多重匹配)

    Jamie's Contact Groups Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/ ...

  7. POJ 2289——Jamie's Contact Groups——————【多重匹配、二分枚举匹配次数】

    Jamie's Contact Groups Time Limit:7000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I ...

  8. POJ2289 Jamie's Contact Groups —— 二分图多重匹配/最大流 + 二分

    题目链接:https://vjudge.net/problem/POJ-2289 Jamie's Contact Groups Time Limit: 7000MS   Memory Limit: 6 ...

  9. Poj 2289 Jamie's Contact Groups (二分+二分图多重匹配)

    题目链接: Poj 2289 Jamie's Contact Groups 题目描述: 给出n个人的名单和每个人可以被分到的组,问将n个人分到m个组内,并且人数最多的组人数要尽量少,问人数最多的组有多 ...

随机推荐

  1. Android之断点续传下载(转)

    Android之断点续传下载http://www.cnblogs.com/zxl-jay/archive/2011/10/09/2204195.html

  2. bzoj 3853 : GCD Array

    搬运题解Claris:1 n d v相当于给$a[x]+=v[\gcd(x,n)=d]$ $\begin{eqnarray*}&&v[\gcd(x,n)=d]\\&=& ...

  3. git的一些常见问题

    from:http://hi.baidu.com/mvp_xuan/blog/item/2ba062d8cd2c9fc939012fae.html 关于linux上建库等操作请看文章: http:// ...

  4. Betsy Ross Problem

    Matlab学习中的betsy ross 问题.用matlab函数画1777年的美国国旗. 五角星绘制部分是自己想出来的方法去画上的.具体代码参考如下. 先是绘制矩形的函数 function Draw ...

  5. vue 混入的理解

  6. [POI2007]Zap

    bzoj 1101: [POI2007]Zap Time Limit: 10 Sec  Memory Limit: 162 MB[Submit][Status][Discuss] Descriptio ...

  7. 翻译: 星球生成 I

    翻译: 星球生成 I 本文翻译自Planet Generation - Part I 译者: FreeBlues 以下为译文: 概述 我一直是一个过程内容生成的爱好者, 它允许你创建一个甚至不断改变的 ...

  8. 网站监控系统安装部署(zabbix,nagios)

    zabbix分布式监控系统安装部署 官方网站链接 https://www.zabbix.com/documentation/2.0/manual/installation 安装环境说明 参考地址 ht ...

  9. 2017ACM暑期多校联合训练 - Team 9 1005 HDU 6165 FFF at Valentine (dfs)

    题目链接 Problem Description At Valentine's eve, Shylock and Lucar were enjoying their time as any other ...

  10. 2017ACM暑期多校联合训练 - Team 9 1010 HDU 6170 Two strings (dp)

    题目链接 Problem Description Giving two strings and you should judge if they are matched. The first stri ...