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. iOS 利用UIWebView与JavaScript交互的最简单办法

    这里说的是针对iOS的!并且方法很简单!!并且验证可行的!!! 1, UIWebView调用 JavaScript 的函数: NSString* strValue = [webView stringB ...

  2. Unity复杂的旋转-欧拉角和四元数

    一.欧拉角欧拉角最容易表示,用三个变量X,Y,Z可以直观的表示绕着某个轴的旋转角度. 在Unity里就是Transform组件的Rotation里的X Y Z三个变量代表了欧拉角 二.四元数四元数相比 ...

  3. vue props 下有验证器 validator 验证数据返回true false后,false给default值

    vue props 下有验证器 validator 验证数据返回true false后,false给default值 props: { type: { validator (value) { retu ...

  4. 新时代web组件开发标准

    VUE框架,则是遵行了这个标准. 1.html文件 <!DOCTYPE html><html><head lang="en"> <meta ...

  5. Spring_对缓存的支持

    使用SpringBoot开启缓存分为两步: 开启基于注解的缓存 标注缓存注解即可 如上就是一个简单的缓存示例 默认使用的是ConcurrentHashMap组件用来缓存的 package ustc.a ...

  6. java web开发中常用的协议的使用和java-web 常见的缓冲技术

    一.DNS协议 作用将域名解析为IP   类似于我们只需要知道中央一台,中央二台,而不需要知道它的频率,方便记忆. java dns 域名解析协议实现 1 域名解析,将域名可转换为ip地址InetAd ...

  7. pooling需要注意的一个地方

    max pooling 在不同的 depth 上是分开执行的,且不需要参数控制.也就是说,pooling之后,feature map的维度不会改变

  8. SQL Server数据库的除法默认向下取整,要返回小数的解决方法

    num1; / 1000.0 num2; * 1.0 num3; num4; 结果:

  9. java 数据库(二)

    1.SQL概述 1.什么是SQL(了解): 结构化查询语言,是一种功能齐全的数据库语言.在使用它时,只需要发出“做什么”的命令,“怎么做”是不用使用者考虑的 SQL被美国国家标准局(ANSI)确定为关 ...

  10. Hadoop集群安装指南(CHD5.9.1)(分布式+图文详解)

    centos7.1,CDH5.9.1,3台机器,终极指导安装 下载链接如下: 安装文件下载链接如下: 链接:https://pan.baidu.com/s/1RQYNiWn9a-T8GXcCsoDBs ...