Optimal Milking
Time Limit: 2000MS   Memory Limit: 30000K
Total Submissions: 16461   Accepted: 5911
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
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <time.h>
#include <string>
#include <map>
#include <stack>
#include <vector>
#include <set>
#include <queue>
#define inf 0x3f3f3f3f
#define mod 10000
typedef long long ll;
using namespace std;
const int N=;
const int M=;
int power(int a,int b,int c){int ans=;while(b){if(b%==){ans=(ans*a)%c;b--;}b/=;a=a*a%c;}return ans;}
int dis[N][N];
int w[N][N];
bool sign[N][N];
bool used[N];
int k,c,n,m;
void Build_Graph(int min_max)
{
memset(w,,sizeof(w));
for(int i=;i<=k;i++)w[][i]=m;
for(int i=k+;i<=n;i++)w[i][n+]=;
for(int i=;i<=k;i++){
for(int j=k+;j<=n;j++){
if(dis[i][j]<=min_max) w[i][j]=;
}
}
}
bool BFS()
{
memset(used,false,sizeof(used));memset(sign,,sizeof(sign));
queue<int>q;
q.push();used[]=true;
while(!q.empty()){
int t=q.front();q.pop();
for(int i=;i<=n+;i++){
if(!used[i]&&w[t][i]){
q.push(i);
used[i]=true;
sign[t][i]=;
}
}
}
if(used[n+])return true;
return false;
}
int DFS(int v,int sum)
{
if(v==n+)return sum;
int s=sum,t;
for(int i=;i<=n+;i++){
if(sign[v][i]){
t=DFS(i,min(w[v][i],sum));
w[v][i]-=t;
w[i][v]+=t;
sum-=t;
}
}
return s-sum;
}
int main()
{
scanf("%d%d%d",&k,&c,&m);
n=k+c;
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
scanf("%d",&dis[i][j]);
if(!dis[i][j])dis[i][j]=inf;
}
}
for(int k=;k<=n;k++){
for(int i=;i<=n;i++){
if(dis[i][k]!=inf){
for(int j=;j<=n;j++){
dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
}
}
}
}
int l=,r=;
while(l<r){
int mid=(l+r)/;
int ans=;
Build_Graph(mid);
while( BFS() )ans+=DFS(,inf);//Dinic求最大流
if(ans>=c) r=mid;
else l=mid+;
}
printf("%d\n",r);
return ;
}

POJ2112 Optimal Milking (网络流)(Dinic)的更多相关文章

  1. POJ2112 Optimal Milking —— 二分图多重匹配/最大流 + 二分

    题目链接:https://vjudge.net/problem/POJ-2112 Optimal Milking Time Limit: 2000MS   Memory Limit: 30000K T ...

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

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

  3. POJ2112 Optimal Milking 【最大流+二分】

    Optimal Milking Time Limit: 2000MS   Memory Limit: 30000K Total Submissions: 12482   Accepted: 4508 ...

  4. POJ2112 Optimal Milking

    Optimal Milking Time Limit: 2000MS   Memory Limit: 30000K Total Submissions: 17811   Accepted: 6368 ...

  5. [Poj2112][USACO2003 US OPEN] Optimal Milking [网络流,最大流][Dinic+当前弧优化]

    题意:有K个挤奶机编号1~K,有C只奶牛编号(K+1)~(C+K),每个挤奶机之多能挤M头牛,现在让奶牛走到挤奶机处,求奶牛所走的最长的一条边至少是多少. 题解:从起点向挤奶机连边,容量为M,从挤奶机 ...

  6. poj2112 Optimal Milking --- 最大流量,二分法

    nx一个挤奶器,ny奶牛,每个挤奶罐为最m奶牛使用. 现在给nx+ny在矩阵之间的距离.要求使所有奶牛挤奶到挤奶正在旅程,最小的个体奶牛步行距离的最大值. 始感觉这个类似二分图匹配,不同之处在于挤奶器 ...

  7. POJ-2112 Optimal Milking(floyd+最大流+二分)

    题目大意: 有k个挤奶器,在牧场里有c头奶牛,每个挤奶器可以满足m个奶牛,奶牛和挤奶器都可以看成是实体,现在给出两个实体之间的距离,如果没有路径相连,则为0,现在问你在所有方案里面,这c头奶牛需要走的 ...

  8. [USACO2003][poj2112]Optimal Milking(floyd+二分+二分图多重匹配)

    http://poj.org/problem?id=2112 题意: 有K个挤奶器,C头奶牛,每个挤奶器最多能给M头奶牛挤奶. 每个挤奶器和奶牛之间都有一定距离. 求使C头奶牛头奶牛需要走的路程的最大 ...

  9. POJ2112 Optimal Milking(最大流)

    先Floyd求牛到机器最短距离,然后二分枚举最长的边. #include<cstdio> #include<cstring> #include<queue> #in ...

随机推荐

  1. Rhel6-heartbeat配置文档

    系统环境: rhel6 x86_64 iptables and selinux disabled 主机: 192.168.122.119 server19.example.com 192.168.12 ...

  2. 配置Java环境-20160613

    http://jingyan.baidu.com/article/870c6fc33e62bcb03fe4be90.html   1.安装JDK,参照目录   在D:\Program Files\ec ...

  3. oracle安装后登录

    运行 sqlplus回车 longon as sysdba回车 回车 这样就可以登录了. SQL>create user username identified by password; SQL ...

  4. javaNIO是什么?由那几部分组成?各部分的作用。

    Java NIO 由以下几个核心部分组成: Channels Buffers Selectors 虽然Java NIO 中除此之外还有很多类和组件,但在我看来,Channel,Buffer 和 Sel ...

  5. xcode开发的6个小技巧

    Xcode是iPhone和iPad开发者用来编码或者开发iOS app的IDE.Xcode有很多小巧但很有用的功能,很多时候我们可能没有注意到它们,也或者我们没有在合适的水平使用这些功能简化我们的iO ...

  6. 使用GoldenGate进行平台迁移和数据库升级(9i->11g)步骤描述

    在一个场景中,需要从Solaris SPARC将数据库迁移到Linux X86-64,同时,数据库版本从原有的oracle 9i(9.2.0.5)升级到11g(11.2.0.4)使用OGG的数据同步功 ...

  7. 对比学习UIKit和AppKit--入门级

    UIKit是用来开发iOS的应用的,AppKit是用来开发Mac应用的,在使用过程中他们很相似,可是又有很多不同之处,通过对比分析它们的几个核心对象,可以避免混淆. UIKit和AppKit都有一个A ...

  8. nslayoutConstraint

    1.vfl的正确编写格式 NSDictionary *dict1 = NSDictionaryOfVariableBindings(_boxV,_headerL,_imageV,_backBtn,_d ...

  9. (function($){...})(jQuery) 含义

    最近在项目js文件末端中发现这样的代码,对于前端技术比较薄弱的我,着实还是有点晕,好在查阅到了相关资料,现解释如下: (function($){  $.plugin = new org.plugin. ...

  10. hdu 2070

    ps:...递推..还是给出公式那种... 代码: #include "stdio.h" #define LL long long LL dp[]; int main(){ int ...