[Usaco2005 feb]Secret Milking Machine 神秘的挤奶机

题目大意:约翰正在制造一台新型的挤奶机,但他不希望别人知道.他希望尽可能久地隐藏这个秘密.他把挤奶机藏在他的农场里,使它不被发现.在挤奶机制造的过程中,他需要去挤奶机所在的地方T(1≤T≤200)次.他的农场里有秘密的地道,但约翰只在返回的时候用它.农场被划分成N(2≤N≤200)块区域,用1到200标号.这些区域被P(1≤P≤40000)条道路连接,每条路有一个小于10^6的长度L.两块区域之间可能有多条道路连接.为了减少被发现的可能,约翰不会两次经过农场上的任何一条道路.当然了,他希望走最短的路. 请帮助约翰寻找这T次从仓库走到挤奶机所在地的路线.仓库是区域1,挤奶机所在地是区域N.我们现在要求的是约翰经过的这些道路中最长的路的长度最小是多少,当然他不能重复走某一条路.请注意,我们要求的不是最短的总路程长度,而是所经过的直揍连接两个区域的道路中最长的道路的最小长度. 数据保证约翰可以找到T条没有重复的从仓库到挤奶机所在区域的路.

数据范围:如题面。


题解

失了智........

首先二分没问题,把最优化问题转换为判定性问题。

接下来怎么办?

其实只需要,原图怎么建图我们怎么建图,然后暴力跑最大流即可........

真是有趣......

代码:

#include <bits/stdc++.h>

#define N 210 

#define M 40010 

using namespace std;

int head[N], to[M << 2], nxt[M << 2], val[M << 2], tot;

queue<int >q;

int dis[N], n, m, t, S, T;

struct Edge {
int x, y, z;
}e[M]; char *p1, *p2, buf[100000]; #define nc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1 ++ ) int rd() {
int x = 0, f = 1;
char c = nc();
while (c < 48) {
if (c == '-')
f = -1;
c = nc();
}
while (c > 47) {
x = (((x << 2) + x) << 1) + (c ^ 48), c = nc();
}
return x * f;
} inline void add(int x, int y, int z) {
to[ ++ tot] = y;
val[tot] = z;
nxt[tot] = head[x];
head[x] = tot; to[ ++ tot] = x;
val[tot] = 0;
nxt[tot] = head[x];
head[x] = tot;
} bool bfs() {
while (!q.empty())
q.pop();
memset(dis, -1, sizeof dis);
dis[S] = 0;
q.push(S);
while (!q.empty()) {
int x = q.front();
q.pop();
for (int i = head[x]; i; i = nxt[i]) {
if (dis[to[i]] == -1 && val[i]) {
dis[to[i]] = dis[x] + 1;
if (to[i] == T)
return true;
q.push(to[i]);
}
}
}
return false;
} int dinic(int x, int fl) {
int tmp = fl;
if (x == T)
return fl;
for (int i = head[x]; i; i = nxt[i]) {
if (dis[to[i]] == dis[x] + 1 && val[i]) {
int mdl = dinic(to[i], min(tmp, val[i]));
if (!mdl) dis[to[i]] = -1;
tmp -= mdl, val[i] -= mdl, val[i ^ 1] += mdl;
if(!tmp) break;
}
}
return fl - tmp;
} void build(int x) {
for (int i = 1; i <= m; i ++ ) {
if (e[i].z <= x) {
add(e[i].x, e[i].y, 1);
add(e[i].y, e[i].x, 1);
}
}
} bool check(int x) {
memset(head, 0, sizeof head);
tot = 1;
build(x);
int ans = 0;
while (bfs()) {
ans += dinic(1, 1 << 30);
}
return ans >= t;
} int main() {
n = rd(), m = rd(), t = rd();
S = 1, T = n;
for (int i = 1; i <= m; i ++ ) {
e[i].x = rd(), e[i].y = rd(), e[i].z = rd();
}
int l = 1, r = 1000001;
while (l < r) {
int mid = (l + r) >> 1;
if (check(mid))
r = mid;
else
l = mid + 1;
}
printf("%d\n", r);
return 0;
}

小结:我能总结些什么么......欧对,这个代码风格是真心好调真心好看,安利一波。

[bzoj1733][Usaco2005 feb]Secret Milking Machine 神秘的挤奶机_网络流的更多相关文章

  1. 【bzoj1733】[Usaco2005 feb]Secret Milking Machine 神秘的挤奶机 二分+网络流最大流

    题目描述 Farmer John is constructing a new milking machine and wishes to keep it secret as long as possi ...

  2. BZOJ1733: [Usaco2005 feb]Secret Milking Machine 神秘的挤奶机

    n<=200个点m<=40000条边无向图,求   t次走不经过同条边的路径从1到n的经过的边的最大值   的最小值. 最大值最小--二分,t次不重边路径--边权1的最大流. #inclu ...

  3. BZOJ 1733: [Usaco2005 feb]Secret Milking Machine 神秘的挤奶机 网络流 + 二分答案

    Description Farmer John is constructing a new milking machine and wishes to keep it secret as long a ...

  4. BZOJ 1733: [Usaco2005 feb]Secret Milking Machine 神秘的挤奶机

    Description 约翰正在制造一台新型的挤奶机,但他不希望别人知道.他希望尽可能久地隐藏这个秘密.他把挤奶机藏在他的农场里,使它不被发现.在挤奶机制造的过程中,他需要去挤奶机所在的地方T(1≤T ...

  5. [BZOJ 1733] [Usaco2005 feb] Secret Milking Machine 【二分 + 最大流】

    题目链接:BZOJ - 1733 题目分析 直接二分这个最大边的边权,然后用最大流判断是否可以有 T 的流量. 代码 #include <iostream> #include <cs ...

  6. POJ 2455 Secret Milking Machine(搜索-二分,网络流-最大流)

    Secret Milking Machine Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9658   Accepted: ...

  7. POJ2455 Secret Milking Machine

    Secret Milking Machine Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12324   Accepted ...

  8. POJ 2455 Secret Milking Machine(最大流+二分)

    Description Farmer John is constructing a new milking machine and wishes to keep it secret as long a ...

  9. 【poj2455】 Secret Milking Machine

    http://poj.org/problem?id=2455 (题目链接) 题意 给出一张n个点,p条边的无向图,需要从1号节点走到n号节点一共T次,每条边只能经过1次,问T次经过的最大的边最小是多少 ...

随机推荐

  1. 小米oj 重拍数组求最大和

     重排数组求最大和 序号:#34难度:困难时间限制:1000ms内存限制:10M 描述 假设有一个n元素的数组(数组的元素索引从1开始),针对这个数组有q个查询请求,每个请求由一对整数li,ri组成, ...

  2. LG2467 地精部落

    题意 给出\(n\),求有几个\(W\)形的\(n\)的全排列(震荡) 思路 可以变求出第二个数比第一个数大的,再翻倍就好 设\(f[i][j]\)表示\(i\)个数中\(j\)个数不符合序列 转移时 ...

  3. win 内网frp反弹到内网liunx

    前提:frp不同系统 但是版本必须完全相同 这是我的两个版本 我这个就是验证frp可以在不同系统之间使用 准备工作 靶机 win2003 ip 192.168.1.132 公网 vps windows ...

  4. 2 - Rich feature hierarchies for accurate object detection and semantic segmentation(阅读翻译)

    Rich feature hierarchies for accurate object detection and semantic segmentation Ross Girshick Jeff ...

  5. GIT上面有的分支,本地却无法检出,也看不到该分支

    正常情况在gitlib上面可以看到代码里面有develop的分支 然而本地在查看所有分支的时候却报错 #查看所有的分支 git branch -a 这种情况是没有更新远程分支的索引,所以这样是看不到的 ...

  6. vue实战教程

    转载自 https://www.cnblogs.com/sunsets/p/7760454.html

  7. docker安装redis,并用配置启动

    1.拉取redis镜像 docker pull redis 2.创建redis本地配置文件 ①.去redis官网下载redis,获取redis.conf文件 ②.修改redis.conf文件相关配置, ...

  8. Content:"\2715",特殊字符和图标

    原文 项目中用到的一些特殊字符和图标 html代码 <div class="cross"></div> css代码 1 2 3 4 5 6 7 8 9 10 ...

  9. pytorch-LeNet网络

    LeNet网络的结构 输入的32x32x1的单通道图片, 第一层网络: 3x3x1x6的卷积层,步长为1, padding = 1, 经过2x2的池化操作 第二层网络: 5x5x6x16的卷积层, 步 ...

  10. ubuntu如何删除刚添加的源?

    答: sudo add-apt-repository -r <source_url> 如: sudo add-apt-repository -r ppa:linaro-maintainer ...