Optimal Milking POJ - 2112 (多重最优匹配+最小费用最大流+最大值最小化 + Floyd)
Time Limit: 2000MS | Memory Limit: 30000K | |
Total Submissions: 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 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)的更多相关文章
- N - Optimal Milking - POJ 2112(二分图多重匹配+Floyd+二分搜索)
题意:有K太挤奶机,C头奶牛,每个挤奶机每天只能为M头奶牛服务,下面给的K+C的矩阵,是形容相互之间的距离,求出来走最远的那头奶牛要走多远 分析:应该先使用floyd求出来点之间的最短路??(不晓得给 ...
- POJ 2195:Going Home(最小费用最大流)
http://poj.org/problem?id=2195 题意:有一个地图里面有N个人和N个家,每走一格的花费是1,问让这N个人分别到这N个家的最小花费是多少. 思路:通过这个题目学了最小费用最大 ...
- poj 2195 二分图带权匹配+最小费用最大流
题意:有一个矩阵,某些格有人,某些格有房子,每个人可以上下左右移动,问给每个人进一个房子,所有人需要走的距离之和最小是多少. 貌似以前见过很多这样类似的题,都不会,现在知道是用KM算法做了 KM算法目 ...
- POJ 2135.Farm Tour 消负圈法最小费用最大流
Evacuation Plan Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4914 Accepted: 1284 ...
- POJ 2195 Going Home(最小费用最大流)
http://poj.org/problem?id=2195 题意 : N*M的点阵中,有N个人,N个房子.让x个人走到这x个房子中,只能上下左右走,每个人每走一步就花1美元,问当所有的人都归位了之 ...
- POJ 2135 Farm Tour (最小费用最大流模板)
题目大意: 给你一个n个农场,有m条道路,起点是1号农场,终点是n号农场,现在要求从1走到n,再从n走到1,要求不走重复路径,求最短路径长度. 算法讨论: 最小费用最大流.我们可以这样建模:既然要求不 ...
- POJ 3422 Kaka's Matrix Travels (最小费用最大流)
POJ 3422 Kaka's Matrix Travels 链接:http://poj.org/problem? id=3422 题意:有一个N*N的方格,每一个方格里面有一个数字.如今卡卡要从左上 ...
- POJ 2135 Farm Tour (网络流,最小费用最大流)
POJ 2135 Farm Tour (网络流,最小费用最大流) Description When FJ's friends visit him on the farm, he likes to sh ...
- poj 3422(最小费用最大流)
题目链接:http://poj.org/problem?id=3422 思路:求从起点到终点走k次获得的最大值,最小费用最大流的应用:将点权转化为边权,需要拆点,边容量为1,费用为该点的点权,表示该点 ...
随机推荐
- 蓝桥杯之大臣的旅费(两次dfs)
Description 很久以前,T王国空前繁荣.为了更好地管理国家,王国修建了大量的快速路,用于连接首都和王国内的各大城市. 为节省经费,T国的大臣们经过思考,制定了一套优秀的修建方案,使得任何一个 ...
- 关于PLC高速计数器使用
今天去面试问我高速计数器,因为没用过,所以直接说--不会.但是自己感觉自己自学电气,说不会太丢人了,所以今天学了PLC的高速计数器.虽然没有书,但是有度娘,还有现成的PLC设备实际检验程序,更有鹏哥和 ...
- 第12章 GPIO输入—按键检测
第12章 GPIO输入—按键检测 全套200集视频教程和1000页PDF教程请到秉火论坛下载:www.firebbs.cn 野火视频教程优酷观看网址:http://i.youku.com/fi ...
- PI monitor error process-RESOURCE_NOT_FOUND-转
事务:sxi_monitor 状态:system error 类型:Request Message Mapping 错误简要:RESOURCE_NOT_FOUND 错误详细信息: <?xml v ...
- Android Studio常用快捷键 - 转
Android Studio常用快捷键 1. Ctrl+D: 集合了复制和粘贴两个操作,如果有选中的部分就复制选中的部分,并在选中部分的后面粘贴出来,如果没有选中的部分,就复制光标所在的行,并在此行的 ...
- 20155232《网络对抗》Exp3 免杀原理与实践
20155232<网络对抗>Exp3 免杀原理与实践 问题回答 1.基础问题回答 (1)杀软是如何检测出恶意代码的? 基于特征码的检测 特征码:一段特征码就是一段或多段数据. 如果一个可执 ...
- 5.Xilinx RapidIO核例子工程源码分析
https://www.cnblogs.com/liujinggang/p/10091216.html 一.软件平台与硬件平台 软件平台: 操作系统:Windows 8.1 64-bit 开发套件:V ...
- 类调用自己的静态方法必须把该方法设置为public
否则调用不了 ParaChecker.isOK(bindingResult); public class ParaChecker { static BaseResult paraCheck(Bindi ...
- L017-linux系统定时任务crond入门小节
L017-linux系统定时任务crond入门小节 oh my god!how old are you? 怎么老是你?没错,我又来了,哈哈哈,今天是我的生日呢,在这么重要的日子里,必须要更一篇学习小节 ...
- docker之搭建私有仓库
一.私有仓库 1.防止网络原因:下载慢,访问不到的情况,需要在内网搭建一个私有仓库. 二.仓库镜像下载 [root@node03 ~]# docker pull registry 三.创建私有仓库容器 ...