链接:

id=2289">http://poj.org/problem?id=2289

意甲冠军:有n个人,m个分组,每一个人能够分配到一些组别。问怎样分能使得人数最多的组别人数最少。

思路:这道题二分+网络流也能够做,我这里是二分图多重匹配的做法。由于一个组别是一对多的关系,所以是多重匹配。我们二分多重匹配的限制,得到最小的限制可使二分图匹配,这个限制就是答案。

网上找的模板

#include<cstring>
#include<string>
#include<fstream>
#include<sstream>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cctype>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<stack>
#include<ctime>
#include<cstdlib>
#include<functional>
#include<cmath>
using namespace std;
#define PI acos(-1.0)
#define MAXN 500010
#define eps 1e-6
#define INF 0x7FFFFFFF
#define LLINF 0x7FFFFFFFFFFFFFFF
#define seed 131
#define MOD 1000000007
#define ll long long
#define ull unsigned ll
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1 const int M=2010;
int bmap[M][M]; //下标0開始
bool bmask[M];
int nx,ny;
int vcy[M];
int cy[M][M];
int limit; //多重匹配限制
bool findpath(int u){
int i,j;
for(i = 0; i < ny; i++){
if(bmap[u][i] && !bmask[i]){
bmask[i] = 1;
if(vcy[i] < limit){
cy[i][vcy[i]++] = u;
return 1;
}
for(j = 0; j < vcy[i]; j++){
if(findpath(cy[i][j])){
cy[i][j] = u;
return 1;
}
}
}
}
return 0;
}
bool MulMatch(){
memset(vcy,0,sizeof(vcy));
for(int i=0; i < nx; i++){
memset(bmask,0,sizeof(bmask));
if(!findpath(i)) return 0;
}
return 1;
}
char str[5000];
int main(){
int i,j,x;
while(scanf("%d%d",&nx,&ny),nx||ny){
memset(bmap,0,sizeof(bmap));
for(i = 0; i < nx; i++){
scanf("%s", str);
gets(str);
stringstream sin(str);
while(sin >> x){
bmap[i][x] = 1;
}
}
int l = 0, r = nx;
while(l < r){
limit = (l + r) / 2;
if(MulMatch()) r = limit;
else l = limit + 1;
}
printf("%d\n", r);
}
return 0;
}

版权声明:本文博客原创文章,博客,未经同意,不得转载。

POJ--2289--Jamie&#39;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. Poj 2289 Jamie's Contact Groups (二分+二分图多重匹配)

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

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

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

  4. POJ 2289 Jamie's Contact Groups 二分图多重匹配 难度:1

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

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

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

  6. POJ 2289 Jamie's Contact Groups & POJ3189 Steady Cow Assignment

    这两道题目都是多重二分匹配+枚举的做法,或者可以用网络流,实际上二分匹配也就实质是网络流,通过枚举区间,然后建立相应的图,判断该区间是否符合要求,并进一步缩小范围,直到求出解.不同之处在对是否满足条件 ...

  7. POJ 2289 Jamie's Contact Groups (二分+最大流)

    题目大意: 有n个人,可以分成m个组,现在给出你每个人可以去的组的编号,求分成的m组中人数最多的组最少可以有多少人. 算法讨论: 首先喷一下这题的输入,太恶心了. 然后说算法:最多的最少,二分的字眼. ...

  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 (二分图多重匹配)

    题意:N个人,M个团体.每个人有属于自己的一些团体编号.将每个人分配到自己属于的团体中,问这个人数最多的团体其人数最小值是多少. 分析:一个一对多的二分图匹配,且是最大值最小化问题.二分图的多重匹配建 ...

随机推荐

  1. boost::signals::signal的使用方法

    吃力的讲完boost::signals的ppt.然后接着就是做练习题. 通过讲ppt,发现有一句话说的真好:你自己知道是一回事.你能给别人讲明确又是另外一回事.真的有些东西你自己理解,可是用语言去非常 ...

  2. 【Spark亚太研究院系列丛书】Spark实战高手之路-第一章 构建Spark集群(第五步)(2)

    把下载下来的"hadoop-2.2.0.tar.gz"复制到"/usr/local/hadoop/"文件夹下并解压: 改动系统配置文件,改动~/.bashrc文 ...

  3. java + memcached安装

    一:安装 (临时获取上手windows实验) 1.下载memcached.exe , 上F:\memcached\ 下 2.在CMD在输入 "F:\memcached\memcached.e ...

  4. Core 1.0中的管道-中间件模式

    ASP.NET Core 1.0中的管道-中间件模式 SP.NET Core 1.0借鉴了Katana项目的管道设计(Pipeline).日志记录.用户认证.MVC等模块都以中间件(Middlewar ...

  5. 工作经常使用的SQL整理,实战篇(二)

    原文:工作经常使用的SQL整理,实战篇(二) 工作经常使用的SQL整理,实战篇,地址一览: 工作经常使用的SQL整理,实战篇(一) 工作经常使用的SQL整理,实战篇(二) 工作经常使用的SQL整理,实 ...

  6. .net SMTP发送Email 更新(可带附件)

    public static void sendEmail(string toAddress, string emailbody)         {             var fromAddre ...

  7. repo总结

    repo刚google使用Python脚本写通话git脚本.主要用于下载.管理Android工程仓库. 1. 下载 repo 的地址: http://android.git.kernel.org/re ...

  8. Oracle 11g client安装和配置。

    数据库和client在不同的机器. 安装前的准备.在安装过程中Oracle数据库server导航到下面的文件夹. 将listener.ora和tnsnames.ora中的host中的localhost ...

  9. Replace是替代 Split分割字符串

    Replace是替代 Split分割字符串string[] ReadText = str.Replace("\r\n", "@").Split('@'); Sp ...

  10. 【设计模式】Template Method模式

    OO基金会 封装 多态 继承 OO原则 封装变化 多用组合,少用继承 针对接口编程.不针对实现编程 为交互对象的松耦合设计而努力 类应该对扩展开放,对改动关闭 依赖抽象,不要依赖详细类 仅仅和朋友交谈 ...