Optimal Milking
Time Limit: 2000MS   Memory Limit: 30000K
Total Submissions: 19347   Accepted: 6907
Case Time Limit: 1000MS
issions: 19347   Accepted: 6907
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

Source

求行走距离的最远的奶牛的至少要走多远。

注意要先用Floyd求每两点之间的最短路。。。。。。

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <queue>
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
const int maxn = , INF = 0x3f3f3f3f;
typedef long long LL; int head[maxn], d[maxn], vis[maxn], p[maxn], f[maxn], way[][];
int n, m, s, t, neng;
int cnt, flow, value; struct node{
int u, v, c, w, next;
}Node[]; void add_(int u, int v, int c, int w)
{
Node[cnt].u = u;
Node[cnt].v = v;
Node[cnt].c = c;
Node[cnt].w = w;
Node[cnt].next = head[u];
head[u] = cnt++;
} void add(int u, int v, int c, int w)
{
add_(u, v, c, w);
add_(v, u, , -w);
} int spfa()
{
queue<int> Q;
for(int i=; i<maxn; i++) d[i] = INF;
d[s] = ;
mem(vis, );
mem(p, -);
Q.push(s);
vis[s] = ;
p[s] = ; f[s] = INF;
while(!Q.empty())
{
int u = Q.front(); Q.pop();
vis[u] = ;
for(int i=head[u]; i!=-; i=Node[i].next)
{
node e = Node[i];
if(d[e.v] > max(d[e.u], e.w) && e.c > )
{
d[e.v] = max(d[e.u], e.w);
p[e.v] = i;
f[e.v] = min(f[u], e.c);
if(!vis[e.v])
{
Q.push(e.v);
vis[e.v] = ;
}
}
}
}
if(p[t] == -) return ;
// cout<< value <<endl;
flow += f[t], value = d[t];
for(int i=t; i!=s; i=Node[p[i]].u)
{
Node[p[i]].c -= f[t];
Node[p[i]^].c += f[t];
}
return ;
} void max_flow()
{
while(spfa());
printf("%d\n",value);
} int main()
{
mem(head, -);
mem(way, INF);
cnt = ;
scanf("%d%d%d", &n, &m, &neng);
for(int i=; i<=n+m; i++)
way[i][i] = ; for(int i=; i<=n+m; i++)
{
for(int j=; j<=n+m; j++)
{
int w;
scanf("%d",&w);
if(w) way[i][j] = w; }
}
for(int k=;k<=n+m;k++)
for(int i=;i<=n+m;i++)
for(int j=;j<=n+m;j++)
way[i][j]=min(way[i][j],way[i][k]+way[k][j]);
for(int i=; i<=m; i++)
for(int j=; j<=n; j++)
if(way[n+i][j] < INF)
add(n+i, j, , way[n+i][j]); s = ; t = n + m + ;
for(int i=; i<=m; i++)
add(s, n+i, , );
for(int j=; j<=n; j++)
add(j, t, neng, );
max_flow(); return ;
}

Optimal Milking POJ - 2112 (多重最优匹配+最小费用最大流+最大值最小化 + Floyd)的更多相关文章

  1. N - Optimal Milking - POJ 2112(二分图多重匹配+Floyd+二分搜索)

    题意:有K太挤奶机,C头奶牛,每个挤奶机每天只能为M头奶牛服务,下面给的K+C的矩阵,是形容相互之间的距离,求出来走最远的那头奶牛要走多远 分析:应该先使用floyd求出来点之间的最短路??(不晓得给 ...

  2. POJ 2195:Going Home(最小费用最大流)

    http://poj.org/problem?id=2195 题意:有一个地图里面有N个人和N个家,每走一格的花费是1,问让这N个人分别到这N个家的最小花费是多少. 思路:通过这个题目学了最小费用最大 ...

  3. poj 2195 二分图带权匹配+最小费用最大流

    题意:有一个矩阵,某些格有人,某些格有房子,每个人可以上下左右移动,问给每个人进一个房子,所有人需要走的距离之和最小是多少. 貌似以前见过很多这样类似的题,都不会,现在知道是用KM算法做了 KM算法目 ...

  4. POJ 2135.Farm Tour 消负圈法最小费用最大流

    Evacuation Plan Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4914   Accepted: 1284   ...

  5. POJ 2195 Going Home(最小费用最大流)

    http://poj.org/problem?id=2195 题意 :  N*M的点阵中,有N个人,N个房子.让x个人走到这x个房子中,只能上下左右走,每个人每走一步就花1美元,问当所有的人都归位了之 ...

  6. POJ 2135 Farm Tour (最小费用最大流模板)

    题目大意: 给你一个n个农场,有m条道路,起点是1号农场,终点是n号农场,现在要求从1走到n,再从n走到1,要求不走重复路径,求最短路径长度. 算法讨论: 最小费用最大流.我们可以这样建模:既然要求不 ...

  7. POJ 3422 Kaka&#39;s Matrix Travels (最小费用最大流)

    POJ 3422 Kaka's Matrix Travels 链接:http://poj.org/problem? id=3422 题意:有一个N*N的方格,每一个方格里面有一个数字.如今卡卡要从左上 ...

  8. POJ 2135 Farm Tour (网络流,最小费用最大流)

    POJ 2135 Farm Tour (网络流,最小费用最大流) Description When FJ's friends visit him on the farm, he likes to sh ...

  9. poj 3422(最小费用最大流)

    题目链接:http://poj.org/problem?id=3422 思路:求从起点到终点走k次获得的最大值,最小费用最大流的应用:将点权转化为边权,需要拆点,边容量为1,费用为该点的点权,表示该点 ...

随机推荐

  1. python3 面向对象编程--类的封装和继承

    #python3import refrom urllib import requestimport os class PosterSpider(object):     def __init__(se ...

  2. STS-创建spring配置文件

    1.创建一个bean文件 2.输入文件名applicationContext.xml 3.这里会自动显示模板文件 4.创建后,自动填充头不定义 到这里就可以发现,我们创建spring文件时,需要的配置 ...

  3. 20155233 《网络对抗》Exp7 网络欺诈技术防范

    应用SET工具建立冒名网站 1.要让冒名网站在别的主机上也能看到,需要开启本机的Apache服务,并且要将Apache服务的默认端口改为80,先在kali中使用netstat -tupln |grep ...

  4. Windows下的Anaconda+OpenCV的环境配置

    Windows下的Anaconda+OpenCV的环境配置

  5. RHEL6 最小化系统 编译安装部署zabbix (mysql)

    RHEL6 最小化系统 编译安装部署zabbix (mysql)官方说明详细见:https://www.zabbix.com/documentation/4.0/manual/installation ...

  6. BERT总结:最先进的NLP预训练技术

    BERT(Bidirectional Encoder Representations from Transformers)是谷歌AI研究人员最近发表的一篇论文:BERT: Pre-training o ...

  7. MIT-6.824 MapReduce

    概述 MapReduce是由JeffreyDean提出的一种处理大数据的编程模型,用户定义map和reduce函数,map函数处理原始数据生成一系列键值对中间数据,reduce函数并合相同key的键值 ...

  8. 高可用Kubernetes集群-13. 部署kubernetes-dashboard

    参考文档: Github介绍:https://github.com/kubernetes/dashboard Github yaml文件:https://github.com/kubernetes/d ...

  9. IOTA price analysis

    Iota coinchart Look at the trendline drawn in red color, at the very first beginning of this month, ...

  10. 第二阶段冲刺——two

    个人任务: 王金萱:优化作业查询结果,按学号排列. 马佳慧:测试登录功能并优化. 司宇航:修复博客作业查询功能. 季方:测试博客作业查询功能. 站立会议: 任务看板和燃尽图: