解题报告

农场有k个挤奶机和c头牛,每头牛到每一台挤奶机距离不一样,每台挤奶机每天最多挤m头牛的奶。

寻找一个方案,安排每头牛到某一挤奶机挤奶,使得c头牛须要走的全部路程中的最大路程的最小值。

要使每一头牛都去挤奶,那么建完模型就要推断是否满流。

因为是多源多点的网络,如果源点0,汇点n+1(n=k+c)

源点到每一头牛的容量为1,每一台机器到汇点的容量为m;用flody求出随意一头牛到随意一台机器的最短路;

对于取最大距离的最小值能够用二分来找。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#define inf 99999999
#define K 33
#define C 210
using namespace std;
int k,c,m,mmap[K+C][K+C],l[K+C],edge[K+C][K+C],n;
void flody()
{
for(int l=1; l<=n; l++)
{
for(int i=1; i<=n; i++)
{
for(int j=1; j<=n; j++)
{
if(mmap[i][j]>mmap[i][l]+mmap[l][j])
mmap[i][j]=mmap[i][l]+mmap[l][j];
}
}
}
}
int bfs()
{
memset(l,-1,sizeof(l));
queue<int>Q;
Q.push(0);
l[0]=0;
while(!Q.empty())
{
int u=Q.front();
Q.pop();
for(int i=0; i<=n+1; i++)
{
if(edge[u][i]&&l[i]==-1)
{
l[i]=l[u]+1;
Q.push(i);
}
}
}
if(l[n+1]>0)return 1;
else return 0;
}
void G(int mid)
{
int i,j;
memset(edge,0,sizeof(edge));
for(i=1; i<=k; i++)
edge[i][n+1]=m;
for(i=k+1; i<=n; i++)
edge[0][i]=1;
for(i=k+1; i<=n; i++)
{
for(j=1; j<=k; j++)
{
if(mmap[i][j]<=mid)
edge[i][j]=1;
else edge[i][j]=0;
}
}
}
int dfs(int x,int f)
{
int a;
if(x==n+1)return f;
for(int i=0; i<=n+1; i++)
{
if(edge[x][i]&&l[i]==l[x]+1&&(a=dfs(i,min(f,edge[x][i]))))
{
edge[x][i]-=a;
edge[i][x]+=a;
return a;
}
}
return 0;
}
int dinic(int mid)
{
int ans=0,a;
G(mid);
while(bfs())
while(a=dfs(0,inf))
ans+=a;
return ans;
}
int main()
{
int i,j;
while(~scanf("%d%d%d",&k,&c,&m))
{
n=k+c;
for(i=1; i<=n; i++)
{
for(j=1; j<=n; j++)
{
scanf("%d",&mmap[i][j]);
if(!mmap[i][j])
mmap[i][j]=inf;
}
}
flody();
int L=0,R=20000;
while(L<R)
{
int mid=(L+R)/2;
int ans=dinic(mid);
if(ans>=c)R=mid;
else L=mid+1;
}
printf("%d\n",R);
}
return 0;
}

Optimal Milking
Time Limit: 2000MS   Memory Limit: 30000K
Total Submissions: 11664   Accepted: 4238
Case Time Limit: 1000MS

Description

FJ has moved his K (1 <= K <= 30) milking machines out into the cow pastures among the C (1 <= C <= 200) cows. A set of paths of various lengths runs among the cows and the milking machines. The milking machine locations are named by ID numbers 1..K; the cow
locations are named by ID numbers K+1..K+C. 



Each milking point can "process" at most M (1 <= M <= 15) cows each day. 



Write a program to find an assignment for each cow to some milking machine so that the distance the furthest-walking cow travels is minimized (and, of course, the milking machines are not overutilized). At least one legal assignment is possible for all input
data sets. Cows can traverse several paths on the way to their milking machine. 

Input

* Line 1: A single line with three space-separated integers: K, C, and M. 



* Lines 2.. ...: Each of these K+C lines of K+C space-separated integers describes the distances between pairs of various entities. The input forms a symmetric matrix. Line 2 tells the distances from milking machine 1 to each of the other entities; line 3 tells
the distances from machine 2 to each of the other entities, and so on. Distances of entities directly connected by a path are positive integers no larger than 200. Entities not directly connected by a path have a distance of 0. The distance from an entity
to itself (i.e., all numbers on the diagonal) is also given as 0. To keep the input lines of reasonable length, when K+C > 15, a row is broken into successive lines of 15 numbers and a potentially shorter line to finish up a row. Each new row begins on its
own line. 

Output

A single line with a single integer that is the minimum possible total distance for the furthest walking cow. 

Sample Input

2 3 2
0 3 2 1 1
3 0 3 2 0
2 3 0 1 0
1 2 1 0 2
1 0 0 2 0

Sample Output

2

POJ2112_Optimal Milking(网洛流最大流Dinic+最短路Flody+二分)的更多相关文章

  1. P3376 【模板】网络最大流( Edmonds-krap、Dinic、ISAP 算法)

    P3376 [模板]网络最大流( Edmonds-krap.Dinic.ISAP 算法) 题目描述 如题,给出一个网络图,以及其源点和汇点,求出其网络最大流. 输入格式 第一行包含四个正整数N.M.S ...

  2. 最大流EK和Dinic算法

    最大流EK和Dinic算法 EK算法 最朴素的求最大流的算法. 做法:不停的寻找增广路,直到找不到为止 代码如下: @Frosero #include <cstdio> #include ...

  3. hdu3313 最大流找关键点,或者最短路找关键点.

    题意:      给你一个有向图,然后给你起点和终点,问你从起点到终点有多少个关键点,如果当前的这个点删除了就无法从起点到终点,那么这个点就是一个关键点.. 思路:      (1)有两种做法,我用的 ...

  4. [源码]ObjectIOStream 对象流 ByteArrayIOStream 数组流 内存流 ZipOutputStream 压缩流

    1.对象流 import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File ...

  5. IO流03_流的分类和概述

    [概述] Java的IO流是实现输入/输出的基础,它可以方便的实现数据的输入/输出操作. Java中把不同的输入/输出源(键盘.文件.网络连接)抽象表述为"流"(Stream). ...

  6. Java基础知识强化之IO流笔记41:字符流缓冲流之复制文本文件案例02(使用 [ newLine() / readLine() ] )(重要)

    1. 使用字符流缓冲流的特殊功能 [ newLine() / readLine() ] 需求:把当前项目目录下的a.txt内容复制到当前项目目录下的b.txt中  数据源: a.txt -- 读取数据 ...

  7. Java基础知识强化之IO流笔记39:字符流缓冲流之复制文本文件案例01

    1. 字符流缓冲流之复制文本文件案例 需求:把当前项目目录下的a.txt内容复制到当前项目目录下的b.txt中 数据源: a.txt -- 读取数据 -- 字符转换流 -- InputStreamRe ...

  8. Java基础知识强化之IO流笔记38:字符流缓冲流之BufferedWriter / BufferedReader使用

    1. 字符流缓冲流: 字符流为了高效读写,也提供了对应的字符缓冲流. BufferedWriter:字符缓冲输出流 BufferedReader:字符缓冲输入流 2. BufferedWriter使用 ...

  9. JAVA之旅(二十七)——字节流的缓冲区,拷贝mp3,自定义字节流缓冲区,读取键盘录入,转换流InputStreamReader,写入转换流,流操作的规律

    JAVA之旅(二十七)--字节流的缓冲区,拷贝mp3,自定义字节流缓冲区,读取键盘录入,转换流InputStreamReader,写入转换流,流操作的规律 我们继续来聊聊I/O 一.字节流的缓冲区 这 ...

随机推荐

  1. android 屏幕尺寸的理解

    对android设备屏幕尺寸单位的理解 一.android移动设备(手机和平板)常用的关于屏幕的一些单位: 1.px:像素点,应该是一个统一的单位,与我们国际单位米(M)应该是一回事,它应该是屏幕尺寸 ...

  2. 单选按钮、复选按钮——axure线框图部件库介绍

    有时候发现这做事情坚持下来是一件很不容易的,写教程也一样,不过听到很多朋友对我说 这个全部是图片的教程 对他们入门帮助很多,我就想想 在坚持坚持把基础部分先完善了! 1. 简单的问卷调查: 您的性别? ...

  3. maven生成war包的两种方式

    war包即对WEB应用程序进行打包,用于应用容器的部署.如在jboss中只要把war包丢入deploy目录下即可发布自己的应用了.打包方式有很多中,很多工具本身就支持此功能.下面主要介绍通过maven ...

  4. javascript 中对this关键字的一些理解

    var self = this 可能会觉得奇怪为什么我会定义一个_self的变量, 因为在js里,this不用对于其他的对象语言,他的解析过程与运行过程中this会改变的.这里简单说说js里this的 ...

  5. 阿里巴巴 web前端性能优化进阶路

    Web前端性能优化WPO,相信大多数前端同学都不会陌生,在各自所负责的站点页面中,也都会或多或少的有过一定的技术实践.可以说,这个领域并不缺乏成熟技术理论和技术牛人:例如Yahoo的web站点性能优化 ...

  6. HDU 4070 Phage War

    贪心,t 大的放到前面...因为感染所有cell需要的phage的总数是一定的,所以产生phage需要的时间是一定的,只需要考虑用来感染的时间,这样考虑的话,把 t 小的放后面的话,可以发现总时间的最 ...

  7. Swift - 使用socket进行通信(附聊天室样例)

    在Swift开发中,如果我们需要保持客服端和服务器的长连接进行双向的数据通信,使用socket是一种很好的解决方案. 下面通过一个聊天室的样例来演示socket通信,这里我们使用了一个封装好的sock ...

  8. 14.6.7?Limits on InnoDB Tables InnoDB 表的限制

    14.6.7?Limits on InnoDB Tables InnoDB 表的限制 警告: 不要把MySQL system tables 从MyISAM 到InnoDB 表. 这是不支持的操作,如果 ...

  9. 基础知识(9)- Swing用户界面组件

    9.1 Swing和模型-视图-控制器设计模式  9.1.1 设计模式  9.1.2 模型-视图-控制器模式  9.1.3 Swing按钮的模型-视图-控制器分析 9.2 布局管理概述  9.2.1 ...

  10. Java学习JVM搞搞Jconsole呗

    无意间翻到这条博客:http://www.blogjava.net/zhvfeng/archive/2010/08/04/327956.html 这里还有个讲解的:http://www.kafka01 ...