题意:

      给你一些名单,和每个名单可以放在哪个分组里,现在要求你把所有的人都分到一个他属于的分组(之一),然后问你分组中最多的那个人数最少是多少...

思路:

     二分最多的最少,然后用最大流去判断分组是否合理,建图如下

         

    s 到 所有人连一条边 流量是1

    所有分组 到 t 连一条边,流量是mid

    然后把所有人和自己属于的分组连边,流量1

    

    跑一边最大流,如果答案等于 N(人数) 那么当前二分满足

    up = mid - 1 ........


#include<stdio.h>
#include<string.h>
#include<queue> #define N_node 1500 + 50
#define N_edge 2000000 + 10000
#define INF 1000000000

using namespace
std; typedef struct
{
int
to ,next ,cost;
}
STAR; typedef struct
{
int
x ,t;
}
DEP; typedef struct
{
int
a ,b;
}
EDGE; STAR E[N_edge];
DEP xin ,tou;
EDGE edge[N_edge];
int
list[N_node] ,tot;
int
list1[N_node];
int
deep[N_node];
char
str[1000000]; void add(int a ,int b ,int c)
{

E[++tot].to = b;
E[tot].cost = c;
E[tot].next = list[a];
list[a] = tot; E[++tot].to = a;
E[tot].cost = 0;
E[tot].next = list[b];
list[b] = tot;
} int
minn(int x ,int y)
{
return
x < y ? x : y;
} bool
BFS_deep(int s ,int t ,int n)
{

memset(deep ,255 ,sizeof(deep));
xin.x = s;
xin.t = 0;
deep[s] = 0;
queue<DEP>q;
q.push(xin);
while(!
q.empty())
{

tou = q.front();
q.pop();
for(int
k = list[tou.x] ;k ;k = E[k].next)
{

xin.x = E[k].to;
xin.t = tou.t + 1;
if(!
E[k].cost || deep[xin.x] != -1)
continue;

deep[xin.x] = xin.t;
q.push(xin);
}
}
for(int
i = 0 ;i <= n ;i ++)
list1[i] = list[i];
return
deep[t] != -1;
} int
DFS_flow(int s ,int t ,int flow)
{
if(
s == t) return flow;
int
nowflow = 0;
for(int
k = list1[s] ;k ;k = E[k].next)
{

list1[s] = k;
int
to = E[k].to;
int
c = E[k].cost;
if(
deep[to] != deep[s] + 1 || ! E[k].cost)
continue;
int
tmp = DFS_flow(to ,t ,minn(c ,flow - nowflow));
nowflow += tmp;
E[k].cost -= tmp;
E[k^1].cost += tmp;
if(
nowflow == flow) break;
}
if(!
nowflow) deep[s] = 0;
return
nowflow;
} int
DINIC(int s ,int t ,int n)
{
int
ans = 0;
while(
BFS_deep(s ,t ,n))
{

ans += DFS_flow(s ,t ,INF);
}
return
ans;
} bool
ok(int mid ,int tt ,int n ,int m)
{

memset(list ,0 ,sizeof(list));
tot = 1;
int
i;
for(
i = 1 ;i <= n ;i ++)
add(0 ,i ,1);
for(
i = 1 ;i <= m ;i ++)
add(n + i ,n + m + 1 ,mid);
for(
i = 1 ;i <= tt ;i ++)
add(edge[i].a ,edge[i].b + n ,1);
return
DINIC(0 ,n + m + 1 ,n + m + 1) == n;
} int main ()
{
int
n ,m ,i ,j;
while(~
scanf("%d %d" ,&n ,&m) && n + m)
{

getchar();
int
tt = 0;
for(
i = 1 ;i <= n ;i ++)
{

gets(str);
int
l = strlen(str) - 1;
j = 0;
while(
str[j] != ' ')
j++;
int
num = 0;
for(
j++ ;j <= l ;j ++)
{
if(
str[j] == ' ')
{

edge[++tt].a = i;
edge[tt].b = num + 1;
num = 0;
continue;
}

num = num * 10 + str[j] - 48;
}

edge[++tt].a = i;
edge[tt].b = num + 1;
} int
low ,up ,mid;
low = 0 ,up = n;
int
ans;
while(
low <= up)
{

mid = (low + up) >> 1;
if(
ok(mid ,tt ,n ,m))
{

ans = mid;
up = mid - 1;
}
else

low = mid + 1;
}

printf("%d\n" ,ans);
}
return
0;
}



1669 DINIC+二分的更多相关文章

  1. POJ 2391 Ombrophobic Bovines (Floyd + Dinic +二分)

    Ombrophobic Bovines Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11651   Accepted: 2 ...

  2. POJ--2112--Optimal Milking【Floyd+Dinic+二分答案】

    链接:http://poj.org/problem?id=2112 题意:有k个挤奶器.编号1~k,c头牛,编号k+1~k+c,每一个挤奶器最多能给m头牛挤奶,给你一个k+c的邻接矩阵.要求每头牛都能 ...

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

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

  4. poj 2112 floyd+Dinic最大流+二分最小值

    题目大意是: K台挤奶机器,C头牛,K不超过30,C不超过200,每台挤奶机器最多可以为M台牛工作,给出这些牛和机器之间,牛和牛之间,机器与机器之间的距离,在保证让最多的牛都有机器挤奶的情况下,给出其 ...

  5. POJ2112_Optimal Milking(网洛流最大流Dinic+最短路Flody+二分)

    解题报告 农场有k个挤奶机和c头牛,每头牛到每一台挤奶机距离不一样,每台挤奶机每天最多挤m头牛的奶. 寻找一个方案,安排每头牛到某一挤奶机挤奶,使得c头牛须要走的全部路程中的最大路程的最小值. 要使每 ...

  6. POJ 2112 Optimal Milking (Dinic + Floyd + 二分)

    Optimal Milking Time Limit: 2000MS   Memory Limit: 30000K Total Submissions: 19456   Accepted: 6947 ...

  7. luogu3305/bzoj3130 费用流 (二分答案+dinic)

    Bob肯定想挑一个流量最大的边,然后把所有的费用都加给它呗 那Alice就让流量最大的边尽量小呗 那就二分一下答案再dinic呗 #include<bits/stdc++.h> #defi ...

  8. HDU 1669 Jamie's Contact Groups(多重匹配+二分枚举)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1669 题目大意: 给你各个人可以属于的组,把这些人分组,使这些组中人数最多的组人数最少,并输出这个人数 ...

  9. Optimal Milking(POJ2112+二分+Dinic)

    题目链接:http://poj.org/problem?id=2112 题目: 题意:有k台挤奶机,c头奶牛,每台挤奶机每天最多生产m的奶,给你每个物品到其他物品的距离(除了物品到自己本省的距离为0外 ...

随机推荐

  1. React开发入门:以开发Todo List为例

    目录 概述 React基本概念 JSX是什么? 设置React APP 初始化APP 应用结构 探索第一个React组件 index.js 变量和props JSX中的变量 组件props props ...

  2. 手工实现一个ThreadPoolExecutor

    以下代码的实现逻辑出自于公众号 码农翻身 <你管这破玩意叫线程池?> - PS:刘欣老师在我心中是软件技术行业的大刘. 线程池接口 public interface Executor { ...

  3. Docker系列——InfluxDB+Grafana+Jmeter性能监控平台搭建(一)

    在做性能测试的时候,重点关注点是各项性能指标,用Jmeter工具,查看指标数据,就是借助于聚合报告,但查看时也并不方便.那如何能更直观的查看各项数据呢?可以通过InfluxDB+Grafana+Jme ...

  4. JSP原理剖析

    什么是JSP JSP长得和html没有区别,但是服务器会把jsp转换为servlet类 JSP(Java Server Page)Java服务器端页面,和Servlet一样,用于动态Web 在jsp之 ...

  5. FreeBSD WIFI 配置

    ee /boot/ loader.conf ee是个编辑器 中写入 rtwn_usb_load="YES" legal.realtek.license_ack=1 在 /etc/ ...

  6. C# 基础 - Enum 的一些操作

    1. int 转换成 enum public enum Suit { Spades, Hearts, Clubs, Diamonds } Suit spades = (Suit)0; Suit hea ...

  7. C# 应用 - 多线程 7) 处理同步数据之 Synchronized code regions (同步代码区域): Monitor 和 lock

    目录: System.Threading.Monitor:提供同步访问对象的机制; lock 是语法糖,是对 Monitor Enter 和 Exit 方法的一个封装 lock 案例 1. Monit ...

  8. 为科学计算而生的Julia——基于Manjaro Linux的安装与入门

    技术背景 Julia是一门为科学计算而生的编程语言,其着重强调了开源.生态与性能.从开源角度来说,相比于Matlab就要友好很多,用户可以免费使用,而且MIT协议应该是最宽松的开源协议之一(截图来自于 ...

  9. 关于在forEach中使用await的问题

    先说需求,根据数组中的ID值,对每个ID发送请求,获取数据进行操作. 首先肯定考虑用forEach 或者 map对数组进行遍历,然后根据值进行操作,但是请求是个异步操作,forEach又是一个同步操作 ...

  10. CPU发展史和相关品牌介绍

    CPU发展史和相关品牌介绍 CPU发展已经有40多年的历史了.我们通常将其分成 六个阶段. (1)第一阶段 (1971年-1973年) .这是4位和8位低档微处理器时代,代表产品是Intel 4004 ...