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的更多相关文章

  1. 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 ...

  2. POJ2289 Jamie's Contact Groups(二分图多重匹配)

    Jamie's Contact Groups Time Limit: 7000MS   Memory Limit: 65536K Total Submissions: 7721   Accepted: ...

  3. Jamie's Contact Groups POJ - 2289(多重匹配 最大值最小化 最大流)

    Jamie's Contact Groups Time Limit: 7000MS   Memory Limit: 65536K Total Submissions: 8567   Accepted: ...

  4. POJ 2289 Jamie's Contact Groups 二分图多重匹配 难度:1

    Jamie's Contact Groups Time Limit: 7000MS   Memory Limit: 65536K Total Submissions: 6511   Accepted: ...

  5. poj 2289 Jamie's Contact Groups【二分+最大流】【二分图多重匹配问题】

    题目链接:http://poj.org/problem?id=2289 Jamie's Contact Groups Time Limit: 7000MS   Memory Limit: 65536K ...

  6. POJ2289:Jamie's Contact Groups(二分+二分图多重匹配)

    Jamie's Contact Groups Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/ ...

  7. POJ 2289——Jamie's Contact Groups——————【多重匹配、二分枚举匹配次数】

    Jamie's Contact Groups Time Limit:7000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I ...

  8. POJ2289 Jamie's Contact Groups —— 二分图多重匹配/最大流 + 二分

    题目链接:https://vjudge.net/problem/POJ-2289 Jamie's Contact Groups Time Limit: 7000MS   Memory Limit: 6 ...

  9. Poj 2289 Jamie's Contact Groups (二分+二分图多重匹配)

    题目链接: Poj 2289 Jamie's Contact Groups 题目描述: 给出n个人的名单和每个人可以被分到的组,问将n个人分到m个组内,并且人数最多的组人数要尽量少,问人数最多的组有多 ...

  10. 图论--网络流--最大流 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 ...

随机推荐

  1. 8 Pratical Examples of Linux “Touch” Command--reference

    In Linux every single file is associated with timestamps, and every file stores the information of l ...

  2. 网站优化的经验和技巧--精简高效的C#

    对大型网站,技术涉及面非常广,对硬件,软件,编程语言,Web Service,防火墙等等有很高要求.    面对大量用户,高并发请求,可以使用高性能服务器,高性能编程语言,高性能数据库,加大带宽等,这 ...

  3. Ext信息提示对话框

    Ext.window.MessageBox是一个工具类,他继承自Ext.window.Windoe对象,用来生成各种风格的信息提示对话框,其实例对象可以通过Ext.MessageBox或Ext.Msg ...

  4. FreeBSD系统更新与软件安装方法

    一.系统更新 freebsd-update fetch freebsd-update install 二.软件源更新(类似yum update.apt-get update) 1.取回源 portsn ...

  5. Linux安装QQ 2017

    网上有很多wineQQ,是基于2012或者2013做的,然而当安装好后登录他会提示版本过来,我在优麒麟的应用商店里找到了一个基于国际版QQ的Wine版本,这里说下安装过程. 先上两张成果图: 下载地址 ...

  6. Android Studio导入aar依赖文件

    以shareSDK为例,导入SMSSDK-2.1.1.aar: 首先将这个aar文件粘贴到libs文件夹下,然后在app目录下的build.gradle里操作 repositories{ flatDi ...

  7. Gym 100187B-A Lot of Joy

    题意:给一个字符串,将每个字符分开放进两个口袋,每次从两个口袋分别拿出一个字符,如果相同则开心,问开心的次数期望是多少. 分析:数学期望题,然而这是我最不拿手的...最后答案是每个字符在字符串出现的次 ...

  8. MITMF使用import error

    安装问题: 1.ubuntu 14.04.安装使用capstone时候,提示出现import error:ERROR: fail to load the dynamic library. 解决方法:将 ...

  9. HierarchicalDataBoundControl 错误

    出现以上错误原因是控件Datasources绑定出错,可能原因是没有区分树形结构的控件如Treeview的绑定与二维数据如datagridview绑定之间的区别.

  10. Hadoop_Block的几种状态_DataNode

    在Hadoop 2.0 中HDFS 引入了 append 和 hflush 功能之后, 需要为 数据块增加新的状态 来尽最大可能的保证数据的一致性. 参阅文档: http://files.cnblog ...