Jamie's Contact Groups

Time Limit: 15000/7000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 747    Accepted Submission(s): 303

Problem Description
Jamie is a very popular girl and has quite a lot of friends, so she always keeps a very long contact list in her cell phone. The contact list has become so long that it often takes a long time for her to browse through the whole list to find a friend's number. As Jamie's best friend and a programming genius, you suggest that she group the contact list and minimize the size of the largest group, so that it will be easier for her to search for a friend's number among the groups. Jamie takes your advice and gives you her entire contact list containing her friends' names, the number of groups she wishes to have and what groups every friend could belong to. Your task is to write a program that takes the list and organizes it into groups such that each friend appears in only one of those groups and the size of the largest group is minimized. 
 
Input
There will be at most 20 test cases. Ease case starts with a line containing two integers N and M. where N is the length of the contact list and M is the number of groups. N lines then follow. Each line contains a friend's name and the groups the friend could belong to. You can assume N is no more than 1000 and M is no more than 500. The names will contain alphabet letters only and will be no longer than 15 characters. No two friends have the same name. The group label is an integer between 0 and M - 1. After the last test case, there is a single line `0 0' that terminates the input.
 
Output
For each test case, output a line containing a single integer, the size of the largest contact group. 
 
Sample Input
3 2
John 0 1
Rose 1
Mary 1
5 4
ACM 1 2 3
ICPC 0 1
Asian 0 2 3
Regional 1 2
ShangHai 0 2
0 0
 
Sample Output
2
2
 
解析:有n个人,m个分组,每个人都可以分到指定的几个组合,问怎么分组使得m个组中的最大组的大小最小。
显然是一对多的关系,然后我们二分 二分图多重匹配 的限制,找到可以使n个人都可以匹配的最小限制就好了。
 
AC代码
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define fillchar(a, x) memset(a, x, sizeof(a))
#define huan printf("\n")
#define debug(a,b) cout<<a<<" "<<b<<" "<<endl
#define ffread(a) fastIO::read(a)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int MAXN = +;
const int MAXM = +;
int uN,vN;
int g[MAXN][MAXM];
int linker[MAXM][MAXN];
bool used[MAXM];
int num[MAXM],limit;
bool dfs(int u)
{
for(int v = ; v < vN; v++)
if(g[u][v] && !used[v])
{
used[v] = true;
if(linker[v][] < limit)
{
linker[v][++linker[v][]] = u;
return true;
}
for(int i = ; i <= linker[v][]; i++)
if(dfs(linker[v][i]))
{
linker[v][i] = u;
return true;
}
}
return false;
}
int hungary()
{
int res = ,flag=;
for(int i = ; i < vN; i++)
linker[i][] = ;
for(int u = ; u < uN; u++)
{
memset(used,false,sizeof(used));
if(dfs(u))
res++;
else
{
flag=;
break;
}
}
return flag;
}
int main()
{
while(scanf("%d%d",&uN,&vN)!=EOF&&uN&&vN)
{
fillchar(g,);
getchar();
for(int i=;i<uN;i++)
{
char s[];
gets(s);
int len=strlen(s);
int num=,jishu=;
for(int j=len-;j>=;j--)
{
if(s[j]==' ')
{
g[i][num]=;
num=jishu=;
}
else if(s[j]>=''&&s[j]<='')
{
num+=(int)(s[j]-'')*pow(,jishu);
jishu++;
}
else
break;
}
}
int l=,r=uN;
while(l<=r)
{
limit=(l+r)/;
//cout<<limit<<endl;
if(!hungary())
r=limit-;
else
l=limit+;
}
printf("%d\n",r+);
}
}

HDU 1669 二分图多重匹配+二分的更多相关文章

  1. hdu 1669(二分图多重匹配)

    Jamie's Contact Groups Time Limit: 15000/7000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/ ...

  2. 稳定的奶牛分配 && 二分图多重匹配+二分答案

    题意: 农夫约翰有N(1<=N<=1000)只奶牛,每只奶牛住在B(1<=B<=20)个奶牛棚中的一个.当然,奶牛棚的容量有限.有些奶牛对它现在住的奶牛棚很满意,有些就不太满意 ...

  3. POJ2112:Optimal Milking(Floyd+二分图多重匹配+二分)

    Optimal Milking Time Limit: 2000MS   Memory Limit: 30000K Total Submissions: 20262   Accepted: 7230 ...

  4. hdu 3605(二分图多重匹配)

    Escape Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Subm ...

  5. HDU 3609 二分图多重匹配

    Escape Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Subm ...

  6. kuangbin带你飞 匹配问题 二分匹配 + 二分图多重匹配 + 二分图最大权匹配 + 一般图匹配带花树

    二分匹配:二分图的一些性质 二分图又称作二部图,是图论中的一种特殊模型. 设G=(V,E)是一个无向图,如果顶点V可分割为两个互不相交的子集(A,B),并且图中的每条边(i,j)所关联的两个顶点i和j ...

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

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

  8. POJ3189:Steady Cow Assignment(二分+二分图多重匹配)

    Steady Cow Assignment Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7482   Accepted: ...

  9. POJ3189 Steady Cow Assignment —— 二分图多重匹配/最大流 + 二分

    题目链接:https://vjudge.net/problem/POJ-3189 Steady Cow Assignment Time Limit: 1000MS   Memory Limit: 65 ...

随机推荐

  1. 毕业设计:HomeFragment(二)

    一.长按item时的响应 在长按item时,我希望能让CheckBox显示出来,并且呼出全选.反选.取消菜单,以及下载.删除.移动.复制操作菜单. 我在具体实现的时候发现处理item布局是一个很大的问 ...

  2. LNMP笔记:解决mail函数不能发送邮件

    用LNMP环境,在探针里测试发送邮件,失败了.已经确定mail()函数是开启的. 问题根源 没有安装或启动 sendmail 组件 解决办法 我是新手,命令不熟,所以写的很详细,老鸟勿喷哦 1.重新安 ...

  3. 在SQLServer使用触发器实现数据完整性

    1.实现数据完整性的手段 在sqlserver中,在服务器端实现数据完整性主要有两种手段:一种是在创建表时定义数据完整性,主要分为:实体完整性.域完整性.和级联参照完整性:实现的手段是创建主键约束.唯 ...

  4. php 批量依照ID建立 文件

    <?php // 登录验证 include_once('inc/conn.php'); // sql查询 $sql="SELECT * FROM zcgl ";// $res ...

  5. About the iOS File System

    两个维度: 1)是否给用户使用: 2)是否持久存储. During installation of a new app, the installer creates a number of conta ...

  6. java 面试题整理

    java面试题 1.接口和抽象类的区别 抽象类 接口 抽象类中可以有默认方法 在java8之前,不能有默认方法 extends implements 抽象类中可以有构造器 接口中不能有构造器 抽象类中 ...

  7. liunx中安装软件的几种方式

    服务器安装包一般有四种方式 1.源代码包安装 自由度高  需要预编译,安装速度慢    2.rpm包手动安装   安装的缺点是文件的关联性太大 3. 二进制tar.gz格式 直接解压即可 如tomca ...

  8. docker 镜像管理操作

    镜像特点 1. 分层存储的文件 2.一个软件运行环境 3.一个镜像可以创建多个容器 4.一种标准交付 5.不包含Linux内核而又精简的Linux操作系统 6.不是一个单一的文件而是由多层构成的,可以 ...

  9. postman的关联,即如何在请求中引用上次请求返回的值

    做接口测试,一定会遇到这种情况,需要拿上次请求的值在本次请求中使用,比如,我们去测试一个东西,要去登录才能做其他的操作,需要拿到登录返回数据中的某些字段,比如,token啊等... 如果发一次请求,就 ...

  10. js实现返回上一页功能

    大家在做 "返回上一页" 这个功能的时候 都是用history.go(-1);来实现的 但这段代码只是简单的使用浏览器的后退功能 从浏览器缓存中取出页面来显示 但我们绝大部分情况都 ...