POJ_2112_Optimal Milking 这里有超级快的网络流板子
Description
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
* 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
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
这个板子有着很多玄学优化 反正特别特别快
题意:k个机器,每个机器最多服务m头牛。
c头牛,每个牛需要1台机器来服务
。告诉你牛与机器每个之间的直接距离。
问:让所有的牛都被服务的情况下,
使走的最远的牛的距离最短,求这个距离。
因为这题求得是最大值得最小值 这个是常见的二分套路
这题行用floyd 跑一个最短路
然后二分枚举长度连边
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <algorithm>
#include <set>
#include <iostream>
#include <map>
#include <stack>
#include <string>
using namespace std;
#define pi acos(-1.0)
#define eps 1e-6
#define fi first
#define se second
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define bug printf("******")
#define mem(a,b) memset(a,b,sizeof(a))
#define fuck(x) cout<<"["<<x<<"]"<<endl
#define f(a) a*a
#define san(n,m) scanf("%d%d",&n,&m)
#define FIN freopen("in.txt","r",stdin)
#define lowbit(x) x&-x
#pragma comment (linker,"/STACK:102400000,102400000")
using namespace std;
const int maxn = ;
typedef long long LL;
const int MX = ;
const int MXE = * MX * MX;
const LL INFLL = 0x3f3f3f3f3f3f3f3fLL;
const int INF = 0x3f3f3f;
struct MaxFlow {
struct Edge {
int v, nxt;
LL w;
} E[MXE];
int tot, num, s, t;
int head[MX];
void init() {
memset (head, -, sizeof (head) );
tot = ;
}
void add (int u, int v, LL w) {
E[tot] = (Edge) {
v, head[u], w
};
head[u] = tot++;
E[tot] = (Edge) {
u, head[v],
};
head[v] = tot++;
}
int d[MX], vis[MX], gap[MX];
void bfs() {
memset (d, , sizeof (d) );
memset (gap, , sizeof (gap) );
memset (vis, , sizeof (vis) );
queue<int>q;
q.push (t);
vis[t] = ;
while (!q.empty() ) {
int u = q.front();
q.pop();
for (int i = head[u]; ~i; i = E[i].nxt) {
int v = E[i].v;
if (!vis[v]) {
d[v] = d[u] + ;
gap[d[v]]++;
q.push (v);
vis[v] = ;
}
}
}
}
int last[MX];
LL dfs (int u, LL f) {
if (u == t) return f;
LL sap = ;
for (int i = last[u]; ~i; i = E[i].nxt) {
int v = E[i].v;
if (E[i].w > && d[u] == d[v] + ) {
last[u] = i;
LL tmp = dfs (v, min (f - sap, E[i].w) );
E[i].w -= tmp;
E[i ^ ].w += tmp;
sap += tmp;
if (sap == f) return sap;
}
}
if (d[s] >= num) return sap;
if (! (--gap[d[u]]) ) d[s] = num;
++gap[++d[u]];
last[u] = head[u];
return sap;
}
LL solve (int st, int ed, int n) {
LL flow = ;
num = n;
s = st;
t = ed;
bfs();
memcpy (last, head, sizeof (head) );
while (d[s] < num) flow += dfs (s, INFLL);
return flow;
}
} F;
int mp[][];
int k, c, m; int check(int mid) {
F.init();
for (int i = ; i <= k ; i++) {
F.add(, i, m);
for (int j = k + ; j <= k + c ; j++ )
if (mp[i][j] <= mid) F.add(i, j, );
}
for (int i = k + ; i <= k + c ; i++)
F.add(i, k + c + , );
if ((int)(F.solve( , k + c + , k + c + )) == c) return ;
return ;
}
int main() {
while(~scanf("%d%d%d", &k, &c, &m)) {
for (int i = ; i <= k + c ; i++)
for (int j = ; j <= k + c ; j++) {
scanf("%d", &mp[i][j]);
if (i != j && !mp[i][j]) mp[i][j] = INF;
}
int num = k + c;
for(int q = ; q <= num; q++)
for(int i = ; i <= num; i++)
for(int j = ; j <= num; j++)
if(mp[i][j] > mp[i][q] + mp[q][j]) mp[i][j] = mp[i][q] + mp[q][j];
int low = , high = INF, mid, ans = ;
while(low <= high) {
mid = (low + high) >> ;
if (check(mid)) {
ans = mid;
high = mid - ;
} else low = mid + ;
}
printf("%d\n", ans);
}
return ;
}
POJ_2112_Optimal Milking 这里有超级快的网络流板子的更多相关文章
- Linux文件系统,ntfs分区显示只读文件系统,提示超级快损坏
		背景:某天当我打开自己的设备,突然发现ntfs分区无法写入任何文件,提示为只读文件系统,具体现象如下: 修复过程:排除权限问题,使用fsck进行修复无果后,使用e2fsck进行修复 显示超级快损坏,这 ... 
- C++ 加速(卡常)技巧【超级 快读、快写】
		C++ \texttt{C++} C++ 加速技巧 快读快写 快读 inline int read() { int x = 0, w = 0; char ch = 0; while (!isdigit ... 
- 【bzoj1733】[Usaco2005 feb]Secret Milking Machine 神秘的挤奶机  二分+网络流最大流
		题目描述 Farmer John is constructing a new milking machine and wishes to keep it secret as long as possi ... 
- uvloop —— 超级快的 Python 异步网络框架
		简短介绍 asyncio是遵循Python标准库的一个异步 I/O框架.在这篇文章里,我将介绍 uvloop: 可以完整替代asyncio事件循环.uvloop是用Cython写的,基于 libuv. ... 
- [bzoj1733][Usaco2005 feb]Secret Milking Machine 神秘的挤奶机_网络流
		[Usaco2005 feb]Secret Milking Machine 神秘的挤奶机 题目大意:约翰正在制造一台新型的挤奶机,但他不希望别人知道.他希望尽可能久地隐藏这个秘密.他把挤奶机藏在他的农 ... 
- Pollard_rho定理 大数的因数个数  这个板子超级快
		https://nanti.jisuanke.com/t/A1413 AC代码 #include <cstdio> #include <cstring> #include &l ... 
- 网络流板子/费用流板子 2018南京I题+2016青岛G题
		2018南京I题: dinic,链式前向星,数组队列,当前弧优化,不memset全部数组,抛弃满流点,bfs只找一条增广路,每次多路增广 #include <bits/stdc++.h> ... 
- 【COGS 14】 [网络流24题] 搭配飞行员 网络流板子题
		用网络流水二分图的模型(存一下板子) #include <cstdio> #include <cstring> #include <algorithm> #defi ... 
- 新版本NDK环境结构(避Cygwin,超快)
		曾经做Android的项目要用到NDK就必需要下载NDK,下载安装Cygwin(模拟Linux环境用的),下载CDT(Eclipse C/C++开发插件),还要配置编译器,环境变量... 麻烦到不想说 ... 
随机推荐
- Spring Cloud(十一):服务网关 Zuul(过滤器)【Finchley 版】
			Spring Cloud(十一):服务网关 Zuul(过滤器)[Finchley 版] 发表于 2018-04-23 | 更新于 2018-05-07 | 在上篇文章中我们了解了 Spring ... 
- 【模板】DFS
			int dx[] = { 0,1,0,-1 }; int dy[] = { 1,0,-1,0 }; void dfs()//参数用来表示状态 { if (到达终点状态) { ...//根据题意来添加 ... 
- 【转载】android 常用开源框架
			对于Android初学者以及对于我们菜鸟,这些大神们开发的轻量级框架非常有用(更别说开源的了). 下面转载这10个框架的介绍:(按顺序来吧没有什么排名). 一. Afinal 官方介绍: Afina ... 
- Thunder团队第一周 - Scrum会议6
			Scrum会议6 小组名称:Thunder 项目名称:爱阅app Scrum Master:苗威 工作照片: 参会成员: 王航:http://www.cnblogs.com/wangh013/ 李传康 ... 
- 哈希表 STL map
			计数排序时我们使用一个数组来记录出现的数字的次数,而当数据范围太大时,无法建立一个那么大地数组(而且可能空间利用率很低,太浪费),此时可以改用hash table . binary search tr ... 
- Spring中Controller和RequestMapping的详解
			先看一个简单的实例: @Controller @RequestMapping("/hello") public class anyTypeController{ @RequestM ... 
- python学习笔记03:python的核心数据类型
			从根本上讲,Python是一种面向对象的语言.它的类模块支持多态,操作符重载和多重继承等高级概念,并且以Python特有的简洁的语法和类型,OOP十分易于使用.Python的语法简单,容易上手. Py ... 
- LintCode-378.将二叉查找树转换成双链表
			将二叉查找树转换成双链表 将一个二叉查找树按照中序遍历转换成双向链表. 样例 给定一个二叉查找树: 返回 1<->2<->3<->4<->5. 标签 链 ... 
- Zigbee安全基础篇Part.2
			原文地址: https://www.4hou.com/wireless/14252.html 导语:本文将会探讨ZigBee标准提供的安全模型,用于安全通信的各种密钥.ZigBee建议的密钥管理方法以 ... 
- week12 201621044079 流与文件
			作业12-流与文件 1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多流与文件相关内容. 2. 面向系统综合设计-图书馆管理系统或购物车 使用流与文件改造你的图书馆管理系统或购物车 ... 
