Jamie's Contact Groups

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

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
 
Source
 
题意:有n个人的信息,这些人被记录在m本记事本上,一个人可能出现在多本记事本上,现在想要将这些人在这m本记事本上出现次数有且只有一次,所以要在一些记事本上删掉一些人名,问删掉之后这m本记事本里面最多人名的记事本的最小值应该是多少?
在二分图最大匹配中,每个点(不管是X方点还是Y方点)最多只能和一条匹配边相关联,然而,我们经常遇到这种问题,即二分图匹配中一个点可以和多条匹配边相关联,但有上限,或者说,Li表示点i最多可以和多少条匹配边相关联。
具体到这个题,那么我们删完之后一个人可以对应多个记事本,所以我们可以去二分上限,得到最小的上限。
#include<iostream>
#include<cstdio>
#include<cstring>
#include <algorithm>
#include <math.h>
using namespace std;
const int N = ;
int n,m,cap;
char str[];
int graph[N][N];
int linker[N][N],link[N];
bool vis[N];
bool dfs(int u){ ///多重匹配,从一端到多端进行匹配
for(int v=;v<m;v++){
if(graph[u][v]&&!vis[v]){
vis[v] = true;
if(link[v]<cap){
linker[v][link[v]++] = u;
return ;
}
for(int i=;i<link[v];i++){
if(dfs(linker[v][i])){
linker[v][i] = u;
return true;
}
}
}
}
return false;
}
bool match(int mid){
cap = mid;
memset(link,,sizeof(link));
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)!=EOF,n+m){
char c;
int v;
memset(graph,,sizeof(graph));
getchar();
for(int i=;i<n;i++){
scanf("%s",str);
while(scanf("%c",&c)&&c!='\n'){
scanf("%d",&v);
graph[i][v] = ;
}
}
int l = ,r = n,ans=n;
while(l<=r){
int mid = (l+r)>>;
if(match(mid)){
ans = mid;
r = mid-;
}else l = mid+;
}
printf("%d\n",ans);
}
return ;
}

hdu 1669(二分图多重匹配)的更多相关文章

  1. HDU 1669 二分图多重匹配+二分

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

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

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

  3. hdu 1669(二分+多重匹配)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1669 思路:由于要求minimize the size of the largest group,由此 ...

  4. HDU 3609 二分图多重匹配

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

  5. HDU - 3605 Escape (缩点+最大流/二分图多重匹配)

    题意:有N(1<=N<=1e5)个人要移民到M(1<=M<=10)个星球上,每个人有自己想去的星球,每个星球有最大承载人数.问这N个人能否移民成功. 分析:可以用最大流的思路求 ...

  6. HDU 3605 Escape(二分图多重匹配问题)

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

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

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

  8. HDU3605 Escape —— 二分图多重匹配

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3605 Escape Time Limit: 4000/2000 MS (Java/Others)    ...

  9. hihoCoder 1393 网络流三·二分图多重匹配(Dinic求二分图最大多重匹配)

    #1393 : 网络流三·二分图多重匹配 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 学校的秋季运动会即将开始,为了决定参赛人员,各个班又开始忙碌起来. 小Hi和小H ...

随机推荐

  1. c# 复选下拉框

    引用dll: http://pan.baidu.com/s/1qXa97UO 自定义类: namespace TMI_S { /// <summary> /// 功能描述:自定义多选下拉框 ...

  2. win7 C/C++,QT安装环境总结

    1. 安装VMware,但是不能用,发现是权限问题,解决方式:使用管理员运行模式即可: 2. 安装win7 ultimate x64,找了半天找不到密钥,只要用激活软件,目前来说系统可用 3. 安装 ...

  3. grpc deadlines

    最近在将应用的rpc更换为grpc,使用过程中,发现报“rpc error:code=DeadlineExceeded desc = context deadline exceeded”,这是啥?原来 ...

  4. 【python】python 中的三元表达式(三目运算符)

    python中的三目运算符不像其他语言其他的一般都是 判定条件?为真时的结果:为假时的结果 如 result=5>3?1:0 这个输出1,但没有什么意义,仅仅是一个例子.而在python中的格式 ...

  5. java实现分页功能的类

    package smn.util; public class Pager { private int pageNow; private int pageSize=4; private int tota ...

  6. bootstrap table表格属性、列属性、事件、方法

    留存一份,原文地址http://bootstrap-table.wenzhixin.net.cn/zh-cn/documentation/ 表格参数 表格的参数定义在 jQuery.fn.bootst ...

  7. BZOJ_day5

    32题...今天颓了不想再写了

  8. JRE集成到Tomcat

    将jdk集成到tomcat里面(不用客户安装JRE) 或者 tomcat使用指定的jdk_ 给客户安装软件的时候,也许客户不想你在人家机器的环境变量里设置来设置去,那么就要在tomcat里指定要使用的 ...

  9. java.sql.Date和java.util.Date的不同和相互转换方式

    一:前言 这是我在新的公司写的第一份博客吧,来了又一个星期了吧,但是在来的那几天我真的很迷茫的感觉这里是很不适合我的样子,而且我又是来实习的,我很不愿意啊,自己做的又是java web,最原始的ser ...

  10. shell分发文件脚本

    配置文件scp.conf ssh_hosts=("IP") #需要分发机器的所有IP ssh_ports=("22") ssh_users=("roo ...