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. POJ 2992 求组合数的因子个数

    求C(n,k)的因子个数 C(n,k) = (n*(n-1)*...*(n-k+1))/(1*2*...*k) = p1^k1 * p2^k2 * ... * pt^kt 这里只要计算出分子中素数因子 ...

  2. config、make、make install

    .config/    .configure  (查看该目录下是否有这个文件,如果有makefile,可直接make)  配置 config是一个shell脚本,根据平台的特性生成Makefile文件 ...

  3. 《java版进制转换》

    import java.util.Scanner; class 十进制转成十六进制_2 { public static void main(String[] args) { int num = 0; ...

  4. AppCan相关网站

    AppCan文档中心: http://doc.appcan.cn/#!/guide/handbook AppCan官网: http://www.appcan.cn/index.html

  5. java多线程的协作

    java多线程之间相互协作,主要有join,  yield,  interupt(),  sleep,  wait,  notify,  notifyAll; join: 在一个线程A的代码里面调用另 ...

  6. BZOJ 2292 永远挑战

    最短路. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm&g ...

  7. PHP中的错误处理和异常处理

    错误处理:    1.语法错误    2.运行时的错误    3.逻辑错误 错误报告:        错误E_ERROR        警告E_WARNING        注意E_NOTICE 开发 ...

  8. linux命令:ls

    1.介绍: ls是linux日常操作中用的最多命令,是list的缩写,默认按名称排序列出当前目录和文件,ls --help可以查看帮助. 2.命令格式: ls [OPTION] [FILE] 3.命令 ...

  9. Palindrome_滚动数组&&DP

    Description A palindrome is a symmetrical string, that is, a string read identically from left to ri ...

  10. GridView按钮事件

    1.html代码 <asp:TemplateField HeaderText="操作"> <ItemTemplate> <div style=&quo ...