Drainage Ditches

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 12771    Accepted Submission(s): 6097

Problem Description
Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clover patch. This means that the clover is covered by water for awhile and takes quite a long time to regrow. Thus, Farmer John has built a set of drainage ditches so that Bessie's clover patch is never covered in water. Instead, the water is drained to a nearby stream. Being an ace engineer, Farmer John has also installed regulators at the beginning of each ditch, so he can control at what rate water flows into that ditch. 
Farmer John knows not only how many gallons of water each ditch can transport per minute but also the exact layout of the ditches, which feed out of the pond and into each other and stream in a potentially complex network. 
Given all this information, determine the maximum rate at which water can be transported out of the pond and into the stream. For any given ditch, water flows in only one direction, but there might be a way that water can flow in a circle. 
 
Input
The input includes several cases. For each case, the first line contains two space-separated integers, N (0 <= N <= 200) and M (2 <= M <= 200). N is the number of ditches that Farmer John has dug. M is the number of intersections points for those ditches. Intersection 1 is the pond. Intersection point M is the stream. Each of the following N lines contains three integers, Si, Ei, and Ci. Si and Ei (1 <= Si, Ei <= M) designate the intersections between which this ditch flows. Water will flow through this ditch from Si to Ei. Ci (0 <= Ci <= 10,000,000) is the maximum rate at which water will flow through the ditch.
 
Output
For each case, output a single integer, the maximum rate at which water may emptied from the pond. 
 
Sample Input
5 4
1 2 40
1 4 20
2 4 20
2 3 30
3 4 10
 
Sample Output
50
 
Source
 

题意:给出n个河流,m个点,以及每个河流的流量,求从1到m点的最大流量。

没啥好说的,裸的最大流,试了一下模板,注意模板的下标。。。

#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;
#define ll long long
#define _cle(m, a) memset(m, a, sizeof(m))
#define repu(i, a, b) for(int i = a; i < b; i++)
#define repd(i, a, b) for(int i = b; i >= a; i--)
#define sfi(n) scanf("%d", &n)
#define pfi(n) printf("%d\n", n)
#define sfi2(n, m) scanf("%d%d", &n, &m)
#define pfi2(n, m) printf("%d %d\n", n, m)
#define pfi3(a, b, c) printf("%d %d %d\n", a, b, c)
#define MAXN 105
#define V 55
//const int INF = 0x3f3f3f3f; #define maxn 210
const int inf = 0x3f3f3f3f; struct EK
{
int cap[maxn][maxn];
int flow[maxn][maxn];
int n;
void init(int n)
{
this->n = n;
memset(cap, , sizeof(cap));
}
void addCap(int i, int j, int val)
{
cap[i][j] += val;
}
int solve(int source, int sink)
{
if(source == sink) return inf;///源=汇, 流量无穷大!
static int que[maxn], pre[maxn], d[maxn];
///bfs时的队列; bfs时某点的前驱; 增光路径的流量
int p, q, t;///bfs时的队列底、顶; bfs时当前元素
memset(flow, , sizeof(flow));
while(true)
{
memset(pre, , sizeof(pre));
d[source] = inf;
p = q = ;
que[q++] = source; while(p<q && pre[sink]==-)
{
t = que[p ++];
for(int i = ; i <= n; i ++)
{
if(pre[i]==- && cap[t][i]-flow[t][i]>)
{
///残余=cap-flow
pre[i] = t;
que[q++]=i;
d[i] = min(d[t], cap[t][i]-flow[t][i]);
}
}
//pfi(1000);
}
if(pre[sink]==-) break;///没有增广路径了!
for(int i = sink; i != source; i = pre[i])
{
flow[pre[i]][i] += d[sink];
flow[i][pre[i]] -= d[sink];
}
}
t = ;///当做网络流量
for(int i = ; i <= n; i ++)
{
t += flow[source][i];
//pfi(flow[source][i]);
}
return t;
}
}ek; int main()
{
int n, m;
while(~sfi2(m, ek.n))
{
ek.init(ek.n);
int x, y, z;
repu(i, , m)
{
sfi2(x, y), sfi(z);
ek.addCap(x, y, z);
}
pfi(ek.solve(, ek.n));
}
return ;
}

hdu 1532(最大流)的更多相关文章

  1. HDU 1532 最大流入门

    1.HDU 1532 最大流入门,n个n条边,求第1点到第m点的最大流.只用EK做了一下. #include<bits/stdc++.h> using namespace std; #pr ...

  2. HDU 1532 最大流模板题

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1532 最近在学网络流,学的还不好,先不写理解了,先放模板... 我觉得写得不错的博客:http://blo ...

  3. poj 1273 ---&&--- hdu 1532 最大流模板

    最近在换代码布局,因为发现代码布局也可以引起一个人的兴趣这个方法是算法Edmonds-Karp 最短增广路算法,不知道的话可以百度一下,基于Ford-Fulkerson算法的基础上延伸的 其实我不是很 ...

  4. hdu 1532 最大流

    #include <cstdio> #include <iostream> #include <algorithm> #include <queue> ...

  5. Drainage Ditches (HDU - 1532)(最大流)

    HDU - 1532 题意:有m个点,n条管道,问从1到m最大能够同时通过的水量是多少? 题解:最大流模板题. #include <iostream> #include <algor ...

  6. hdu 1532 Drainage Ditches (最大流)

    最大流的第一道题,刚开始学这玩意儿,感觉好难啊!哎····· 希望慢慢地能够理解一点吧! #include<stdio.h> #include<string.h> #inclu ...

  7. HDU 1532 Drainage Ditches(最大流 EK算法)

    题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=1532 思路: 网络流最大流的入门题,直接套模板即可~ 注意坑点是:有重边!!读数据的时候要用“+=”替 ...

  8. HDU 1532 Drainage Ditches 最大流 (Edmonds_Karp)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1532 感觉题意不清楚,不知道是不是个人英语水平问题.本来还以为需要维护入度和出度来找源点和汇点呢,看 ...

  9. HDU 1532||POJ1273:Drainage Ditches(最大流)

    pid=1532">Drainage Ditches Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/327 ...

随机推荐

  1. struts2-通配符映射(基本没啥卵用)和动态调用

    通配符 使用*代表任意字符 一般在action的name中使用*,并可以使用多个 可以使用{通配符的序号}引用对应的通配符所代表的值,序号从1开始 {0}代表整个URI 匹配规则 首先完全匹配,没有完 ...

  2. c# 中get和post的方法

    用GET发送数据则用REQUEST.QUERYSTRING[''ID'']接收 一.request.aspx 二.request.aspx.cs 三运行效果: 以下是数据发送的途径http://loc ...

  3. 【转】PowerShell入门(六):远程操作

    转至:http://www.cnblogs.com/ceachy/archive/2013/02/20/PowerShell_Remoting.html PowerShell远程操作是远程管理的基础, ...

  4. T-SQL 的简单查询语句

    通配符: “_”: 代表匹配一个字符 “%”: 代表匹配多个字符: []:表示范围,可以包含多个数据 [^] 表示取反 “-“  表示范围 逻辑与 and 逻辑或 or  逻辑非 not 聚会函数 : ...

  5. Android跨进程通信的四种方式

    由于android系统中应用程序之间不能共享内存.因此,在不同应用程序之间交互数据(跨进程通讯)就稍微麻烦一些.在android SDK中提供了4种用于跨进程通讯的方式.这4种方式正好对应于andro ...

  6. 【C++/Qt】Qt中的parent形参

    在 派生类的构造函数初始化列表中 调用 父类的带有参数的构造函数,是为了初始化从父类继承来的成员变量.因为这些变量无法直接初始化,只能采用这种方式初始化. 而在qt中,MainWindow中的某成员变 ...

  7. 特征的转换规则 Transfer Routione

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  8. Codeforces Round #383 (Div. 2) A,B,C,D 循环节,标记,暴力,并查集+分组背包

    A. Arpa’s hard exam and Mehrdad’s naive cheat time limit per test 1 second memory limit per test 256 ...

  9. C#中调用Matlab人工神经网络算法实现手写数字识别

    手写数字识别实现 设计技术参数:通过由数字构成的图像,自动实现几个不同数字的识别,设计识别方法,有较高的识别率 关键字:二值化  投影  矩阵  目标定位  Matlab 手写数字图像识别简介: 手写 ...

  10. iOS - Mac Apache WebDav 服务器配置

    前言 Apache 服务器: Web 服务器,可以支持各种脚本(PHP)的执行,目前世界上使用最为广泛的一种 Web 服务器 WebDav 服务器: 基于 http 协议的 "文件" ...