[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. OFDM时域削峰法降峰均比的原理及影响

    以下是对实验室师兄答疑的转述,经加工后的文字不可避免的存在一些噪声,仅供参考: 时域削峰为非线性变换,效果上相当于将时域中功率较大值的信号点,减去一个合适的“抵消”信号点的功率,使其降低到所设置的门限 ...

  2. EnumHelper.cs

    网上找的,还比较实用的: using System; using System.Collections.Generic; using System.ComponentModel; using Syst ...

  3. webpack给目录起别名

    1. 配置文件目录: build>webpack.base.config.js: resolve: { alias: { '@': resolve('src'), 'styles': resol ...

  4. 在chrome开发者模式中查找你的js文件

    在chrom开发者模式中按ctrl+o查找你的js文件

  5. 初学Javascript,写一个简易的登陆框

    <!--下面是源代码--> <!DOCTYPE html> <html> <head> <meta charset = "utf-8&q ...

  6. JavaWeb_(Hibernate框架)Hibernate中数据查询语句SQL基本用法

    本文展示三种在Hibernate中使用SQL语句进行数据查询基本用法 1.基本查询 2.条件查询 3.分页查询 package com.Gary.dao; import java.util.List; ...

  7. Spring AOP:Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException

    1 报错 Exception encountered during context initialization - cancelling refresh attempt: org.springfra ...

  8. P1439 【模板】最长公共子序列 LCS

    P1439 [模板]最长公共子序列 题解 1.RE的暴力DP O(n2) 我们设dp[i][j]表示,S串的第i个前缀和T串的第j个前缀的最长公共子序列. ◦          分情况: ◦      ...

  9. Activity的生命周期是谁调用的?

    我们知道Activity的生命周期包括onCreate.onStart.onResume.onRestart.onStop.onDestory.onSaveInstanceState.onRestor ...

  10. vue 动态组件,传递参数

    <template> <div class="top"> <div class='nav'> <ul class='navHader'&g ...