hdu 1669(二分图多重匹配)
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
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.
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.
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
2
#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(二分图多重匹配)的更多相关文章
- HDU 1669 二分图多重匹配+二分
Jamie's Contact Groups Time Limit: 15000/7000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/ ...
- hdu 3605(二分图多重匹配)
Escape Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Subm ...
- hdu 1669(二分+多重匹配)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1669 思路:由于要求minimize the size of the largest group,由此 ...
- HDU 3609 二分图多重匹配
Escape Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Subm ...
- HDU - 3605 Escape (缩点+最大流/二分图多重匹配)
题意:有N(1<=N<=1e5)个人要移民到M(1<=M<=10)个星球上,每个人有自己想去的星球,每个星球有最大承载人数.问这N个人能否移民成功. 分析:可以用最大流的思路求 ...
- HDU 3605 Escape(二分图多重匹配问题)
Escape Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Subm ...
- kuangbin带你飞 匹配问题 二分匹配 + 二分图多重匹配 + 二分图最大权匹配 + 一般图匹配带花树
二分匹配:二分图的一些性质 二分图又称作二部图,是图论中的一种特殊模型. 设G=(V,E)是一个无向图,如果顶点V可分割为两个互不相交的子集(A,B),并且图中的每条边(i,j)所关联的两个顶点i和j ...
- HDU3605 Escape —— 二分图多重匹配
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3605 Escape Time Limit: 4000/2000 MS (Java/Others) ...
- hihoCoder 1393 网络流三·二分图多重匹配(Dinic求二分图最大多重匹配)
#1393 : 网络流三·二分图多重匹配 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 学校的秋季运动会即将开始,为了决定参赛人员,各个班又开始忙碌起来. 小Hi和小H ...
随机推荐
- lock关键字的使用
最近在代码中,发现别人使用了lock关键字,为了理解别人写的代码,所以自己对lock关键字的使用研究了下. 微软官方解释,请百度:lock 语句(C# 参考) 微软给了个官网实例代码: class A ...
- java面向对象课程设计-数学表达式计算器
项目简介 设计一个计算器,其能够: 1)由用户输入一个简单的四则运算表达式,求出其计算结果后显示. 2)特殊数学函数,如:绝对值.取整.三角函数.倒数.平方根.平方.立方等. 3)对一定范围内的数字将 ...
- 【python】Python3中出现'gbk' codec can't encode characte的成功解决方法?
亲身测试,所遇问题完全解决!2018/07/08 21:37 环境:windows,Pycharm,python3.6.2 使用Python写文件的时候,或者将网络数据流写入到本地文件的时候,大部分情 ...
- iMuseum
iMuseum 每日环球展览 iMuseum https://itunes.apple.com/cn/app/%E6%AF%8F%E6%97%A5%E7%8E%AF%E7%90%83%E5%B1%95 ...
- oracle补充
索引 索引是若干数据行的关键字的列表,查询数据时,通过索引中的关键字可以快速定位到要访问的记录所在的数据块,从而大大减少读取数据的I/O次数,因此可以显著的提高性能 创建索引的SQL 把下面表中的na ...
- [洛谷P1361]小M的作物
题目大意:将作物种在A,B两地,对于每种作物,种A,B分别有不同的收益,对于一些特殊的作物集合,共同种到A,B集合分别有一些额外收益.求最大收益. 题解:最小割,S向i连容量为$a_i$的边,i向T连 ...
- BZOJ 1101 [POI2007]Zap | 第一道莫比乌斯反(繁)演(衍)
题目: http://www.lydsy.com/JudgeOnline/problem.php?id=1101 题解: http://www.cnblogs.com/mrha/p/8203612.h ...
- LinuxUnix time时间戳的处理转换函数
Linux/Unix time时间戳的处理转换函数 linux下的时间函数 我们在编程中可能会经常用到时间,比如取得系统的时间(获取系统的年.月.日.时.分.秒,星期等),或者是隔一段时间去做某事,那 ...
- 【BZOJ1458】士兵占领 最大流的模板题
我们只要把他们可以有的限制用流量限制,再用两者关系限制一下就可以开心的跑了. #include <cstdio> #include <cstring> #include < ...
- BZOJ2337: [HNOI2011]XOR和路径 期望概率dp 高斯
这个题让我认识到我以往对于图上期望概率的认识是不完整的,我之前只知道正着退还硬生生的AC做过的所有图,那么现在让我来说一下逆退,一般来说对于概率性的东西都只是正推,因为有了他爸爸才有了他,而对于期望性 ...