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. 在自己的工程中使用ijkplayer的功能

    最近在做一个软解视频叠加硬解视频的方案,网上看了很多教程,始终不得要领.虽然ijkplayer提供了ijkplayer-example这个示例工程,但对于初入安卓的人来说,要将ijkplayer整合到 ...

  2. css3纯手写loading效果

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  3. EOS Dawn 3.0 智能合约 -- 新格式

    1.简介 随着EOS Dawn 3.0发布,智能合约的坑又要重新踩了o(╥﹏╥)o:3.0不仅将原来本身就在链里的基础合约独立出来,简单的介绍见3.0合约改变,合约的书写方式也有巨大变化,相比之前更加 ...

  4. docker的安装及基础操作与镜像构建

    仓库配置及安装启动 [root@localhost ~]# yum install -y yum-utils device-mapper-persistent-data lvm2 [root@loca ...

  5. CPP-基础:文字常量区

    内存不可写 char* 先看一个例子 ///////////// //代码1 #include <string> main() { char *buf = "good morni ...

  6. tabs标签页的数据缓存

    一进入tabs标签页默认就将所有标签页的数据请求到,并渲染到页面上, 这样如果数据量太大的话会渲染很久, 我的需求就是点击不同的标签时再请求数据,同时对点击过的标签页数据进行缓存,下次点击时不再重新请 ...

  7. Linux修改网卡名

    问题现象:戴尔机器网卡名为em1,修改为eth0a)由于未发现有/etc/udev/rule.d/70-persistent-net.rules文件,重启后也未发现此文件手动执行/lib/udev/w ...

  8. 第十三章:MFC库与Windows程序开发概述

    主要内容: 1.Windows程序的基本结构 2.MFC库简介 3.使用Visual C++开发Windows程序 具体内容略

  9. Python3--中括号"[]"与冒号":"在列表中的作用

    先来定义两个列表: liststr = ["helloworld","hahahh","123456"] listnum = [1,2,3, ...

  10. fit in gnuplot

    Table of Contents 1. fit-gnuplot 1 fit-gnuplot syntax >> fit [xrange][yrange] function 'datafi ...