Jamie's Contact Groups
poj2289:http://poj.org/problem?id=2289
题意:给定一个规模为n的名单,要将名单中的人归到m个组中,给出每个人可能的分组号,需要确定一种分配方案,是的最大规模的组最小。
题解:很明显的二分。然后把人和组都拆点即可。
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<queue>
#define INF 100000000
using namespace std;
const int N=;
const int M=;
struct Node{
int v;
int f;
int next;
}edge[M];
int n,m,u,v,cnt,sx,ex;
int head[N],pre[N];
int val[N][];//根据题目要求申请
void init(){
cnt=;
memset(head,-,sizeof(head));
}
void add(int u,int v,int w){
edge[cnt].v=v;
edge[cnt].f=w;
edge[cnt].next=head[u];
head[u]=cnt++;
edge[cnt].f=;
edge[cnt].v=u;
edge[cnt].next=head[v];
head[v]=cnt++;
}
bool BFS(){
memset(pre,,sizeof(pre));
pre[sx]=;
queue<int>Q;
Q.push(sx);
while(!Q.empty()){
int d=Q.front();
Q.pop();
for(int i=head[d];i!=-;i=edge[i].next ){
if(edge[i].f&&!pre[edge[i].v]){
pre[edge[i].v]=pre[d]+;
Q.push(edge[i].v);
}
}
}
return pre[ex]>;
}
int dinic(int flow,int ps){
int f=flow;
if(ps==ex)return f;
for(int i=head[ps];i!=-;i=edge[i].next){
if(edge[i].f&&pre[edge[i].v]==pre[ps]+){
int a=edge[i].f;
int t=dinic(min(a,flow),edge[i].v);
edge[i].f-=t;
edge[i^].f+=t;
flow-=t;
if(flow<=)break;
} }
if(f-flow<=)pre[ps]=-;
return f-flow;
}
int solve(){
int sum=;
while(BFS())
sum+=dinic(INF,sx);
return sum;
}
char str[];
int ans[N][N];
int tot[N],top;
void build(int mid){
init();
for(int i=;i<=n;i++){
for(int j=;j<=tot[i];j++){
add(i+n,ans[i][j]+*n,);
}
add(i,i+n,);
add(,i,);
}
for(int i=;i<=m;i++){
add(i+*n,i+*n+m,mid);
add(i+*n+m,*m+*n+,INF);
}
}
int as,temp;
int main() {
while(~scanf("%d%d",&n,&m)&&n) {
init();
as=;
for(int i=;i<=n;i++){
scanf("%s",str);
top=;
while(getchar()!='\n'){
scanf("%d",&temp);
//printf("**%d\n",temp);
ans[i][++top]=++temp;
}
tot[i]=top;
}
int l=,r=n;
sx=,ex=*n+*m+;
while(l<=r){
int mid=(l+r)/;
build(mid);
if(solve()==n){
r=mid-;
as=mid;
}
else
l=mid+;
}
printf("%d\n",as); }
return ;
}
Jamie's Contact Groups的更多相关文章
- POJ 2289 Jamie's Contact Groups / UVA 1345 Jamie's Contact Groups / ZOJ 2399 Jamie's Contact Groups / HDU 1699 Jamie's Contact Groups / SCU 1996 Jamie's Contact Groups (二分,二分图匹配)
POJ 2289 Jamie's Contact Groups / UVA 1345 Jamie's Contact Groups / ZOJ 2399 Jamie's Contact Groups ...
- POJ2289 Jamie's Contact Groups(二分图多重匹配)
Jamie's Contact Groups Time Limit: 7000MS Memory Limit: 65536K Total Submissions: 7721 Accepted: ...
- Jamie's Contact Groups POJ - 2289(多重匹配 最大值最小化 最大流)
Jamie's Contact Groups Time Limit: 7000MS Memory Limit: 65536K Total Submissions: 8567 Accepted: ...
- POJ 2289 Jamie's Contact Groups 二分图多重匹配 难度:1
Jamie's Contact Groups Time Limit: 7000MS Memory Limit: 65536K Total Submissions: 6511 Accepted: ...
- poj 2289 Jamie's Contact Groups【二分+最大流】【二分图多重匹配问题】
题目链接:http://poj.org/problem?id=2289 Jamie's Contact Groups Time Limit: 7000MS Memory Limit: 65536K ...
- POJ2289:Jamie's Contact Groups(二分+二分图多重匹配)
Jamie's Contact Groups Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/ ...
- POJ 2289——Jamie's Contact Groups——————【多重匹配、二分枚举匹配次数】
Jamie's Contact Groups Time Limit:7000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I ...
- POJ2289 Jamie's Contact Groups —— 二分图多重匹配/最大流 + 二分
题目链接:https://vjudge.net/problem/POJ-2289 Jamie's Contact Groups Time Limit: 7000MS Memory Limit: 6 ...
- Poj 2289 Jamie's Contact Groups (二分+二分图多重匹配)
题目链接: Poj 2289 Jamie's Contact Groups 题目描述: 给出n个人的名单和每个人可以被分到的组,问将n个人分到m个组内,并且人数最多的组人数要尽量少,问人数最多的组有多 ...
- 图论--网络流--最大流 POJ 2289 Jamie's Contact Groups (二分+限流建图)
Description Jamie is a very popular girl and has quite a lot of friends, so she always keeps a very ...
随机推荐
- abap中的弹出窗体函数
POPUP_TO_CONFIRM_WITH_MESSAGE 会话框确实处理步骤; 用识别正文POPUP_TO_SELECT_MONTH 日历:弹出 POPUP_TO_C ...
- KDB调试内核
http://www.ibm.com/developerworks/cn/linux/l-kdbug/
- hadoop错误org.apache.hadoop.mapred.TaskAttemptListenerImpl Progress of TaskAttempt
错误: org.apache.hadoop.mapred.TaskAttemptListenerImpl: Progress of TaskAttempt 原因: 错误很明显,磁盘空间不足,但郁闷的是 ...
- JDK中DNS缓存的分析
在JAVA中使用InetAddress.getByName(String host) 方法来获取给定hostname的IP地址.为了减少DNS解析的请求次数,提高解析效率,InetAddress中提供 ...
- NDK开发之调用方法
与NDK开发之访问域中介绍的一样,Java中的方法也是分为两类:实例方法和静态方法.JNI提供了访问两类方法的函数,下面我们一起来看看怎么在C中访问Java中的方法. 我们的MainActivity中 ...
- oracle数据快速删除
上文说了创建数据还原点的事,数据恢复的前提是我们在删除的时候使用了delete命令来删除,delete在删除的过程中会写日志(所以我们的数据才能够恢复),当然,写日志会导致删除速度变慢.如果我们使用t ...
- ssh 无密码登录远程服务器
在讲下文之前,我都默许大家都已经生成了自己的ssh公钥和密钥,在自己的~/.ssh 目录下面,如果没有,请使用 ssh-keygen -t rsa -C "你的邮箱" 命令生成 1 ...
- 版本控制SVN与Eclipse4.4.1集成 ( eclipse svn:E175002错误解决 )
Eclipse版本--Luna Service Release 1(4.4.1) SVN版本-----1.8.X 系统OS-------ubuntu 14.04 LTS 1.通过地址安装 Help-& ...
- jQuery 取值、赋值的基本方法【转藏】
/*获得TEXT.AREATEXT的值*/ var textval = $("#text_id").attr("value"); //或者 var textva ...
- AngularJS Filter用法详解【转+实际测试】 格式化货币
AngularJS内建了一些常用的Filter,我们一一来看一下. currencyFilter(currency): 用途:格式化货币 方法原型: function(amount, currency ...