POJ---1273 Drainage Ditches【最大流】

STM32+OpenCV云台PID调参实战:从震荡到丝滑跟踪的进阶之路 本文详细介绍了基于STM32和OpenCV的跟踪云台PID调参实战经验。从硬件搭建、PID控制原理到调参技巧,系统讲解了如何通过调整比例、积分和微分参数解决系统震荡问题,实现从震荡到丝滑跟踪的进阶过程,特别适合电赛和嵌入式视觉控制开发者参考。 阅读详情

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:点击打开链接


题意:

   赤裸裸的网络流题目。给定点数,边数,每条边的容量,以及源点,汇点,求最大流。

解析:

   通过Ford-Fulkerson算法或者是Dinic算法,通过dfs搜索最小流进行增广路。

Ford-Fulkerson算法:

#include <iostream>
#include <cstring>
#include <algorithm>
#define MAX 205
#define INF 0x7fffffff
using namespace std;

int n,m;
int c[MAX][MAX];
bool pass[MAX];
int dfs(int s,int t,int low);//s为源点,t为汇点,low为当前流
int dfs_max_flow(int s,int t);

int main(void)
{
    int a,b,d;
    while (cin>>n>>m)
    {
        memset(c,0,sizeof(c));
        for (int i=1; i<=n; ++i)
        {
            cin>>a>>b>>d;
            c[a][b]+=d;
        }
        cout<<dfs_max_flow(1,m)<<endl;
    }
    return 0;
}

int dfs(int s,int t,int low)
{
    if (s==t)
        return low;
    pass[s]=1;
    for (int i=1; i<=m; ++i)
    {
        if (!pass[i]&&c[s][i])
        {
            int flow=dfs(i,t,min(low,c[s][i]));
            if(flow>0)  //增广该路径
            {
                c[s][i]-=flow;
                c[i][s]+=flow;
                return flow;
            }
        }
    }
    return 0;
}

int dfs_max_flow(int s,int t)
{
    memset(pass,0,sizeof(pass));
    int maxflow=0,flow;
    while (flow=dfs(s,t,INF)) //不断地增广路径进行搜索,直到无法继续增加才结束
    {
        memset(pass,0,sizeof(pass));
        maxflow+=flow;
    }
    return maxflow;
}

Dinic算法:

#include<iostream>
#include<cstring>
#include<queue>
#define maxn 205
#define INF 0x7fffffff
using namespace std;

int n, m;
int c[maxn][maxn];
int dis[maxn];//dis[i]表示到原点s的层数

bool bfs();
int  dfs(const int x,const int low);

int main(void)
{
    int s,t,d;
    while(cin>>n>>m)
    {
        memset(c,0,sizeof(c));
        for(int i = 0  ; i < m; i++)
        {
            cin>>s>>t>>d;
            c[s][t] += d;
        }
        int ans = 0;
        int res;
        while(bfs())
            while(res = dfs(1,INF))
                ans+= res;
        cout<<ans<<endl;
    }
    return 0;
}

bool bfs()// 重新建图按层数建图
{
    memset(dis,-1,sizeof(dis));
    int k;
    dis[1] = 0;
    queue<int> que;
    que.push(1);
    while(que.size())
    {
        k = que.front();
        que.pop() ;
        for( int i = 1; i<= m; i++)
            if(c[k][i] > 0 && dis[i] < 0 )// 如果 可以  可以到达 但 还没有 访问
            {
                dis[i] = dis[k]+ 1;
                que.push(i);
            }
    }
    if(dis[n] > 0)
        return true;
    else
        return false;
}

int  dfs(const int x,const int low)// 查找路径上的最小的流量
{
    int flow;
    if(x == n)
        return low;
    for(int i = 1; i<= n; i++)
        if(c[x][i] > 0 && dis[i] == dis[x] + 1)
        {
            flow=dfs(i,min(low,c[x][i]));
            if(flow>0)
            {
                c[x][i] -= flow;
                c[i][x] += flow;
                return flow;
            }
        }
    return 0;
}



头歌工程实训答案-机器学习篇之手写体识别篇 第2关:激活函数'''x:负无穷到正无穷的实数'''if x<=0:return 0else:return x#***第3关:反向传播算法import os。 阅读详情

相关推荐

Vivado加上VsCode让你的生活更美好

VsCode与Vivado的灵活使用 引言 ​ 现在大二了,在接触硬件描述语言。Vivado自带的编辑器实在很难用,为了能够“极客”一些,当然是去Google了一下有哪些方法可以取而代之。 ​ 网络上的答案大同小异,基本上都是用的Sublime Text.(我的学长们也几乎都是) 平时码代码的过程中,我习惯与使用VsCode,尤其是在微软收购GitHub之后,Code 简直就是神器了。于是乎…一个...

qq_39498701的博客 10万+

最大流 POJ1273 Drainage Ditches

最大流 POJ1273 Drainage Ditches 题目描述: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 qui...

weixin_30321449的博客 118

Dify 深度进阶:从入门到精通AI应用构建

《Dify进阶指南:从基础到高阶的AI应用开发技巧》 本文深入探讨Dify平台的高级功能与应用开发技巧。首先强调核心概念的深化,包括提示词工程进阶、知识库高效管理和模型参数优化。重点介绍智能体应用的开发方法,如何让AI具备自主规划与执行能力。同时讲解工作流编排、前端集成等实用技术,并分享应用运营优化、成本控制等实践经验。文章还展望了Dify生态的发展趋势,为开发者提供从基础到进阶的完整学习路径,助力打造更智能高效的AI应用。

同名公众号:dify实验室 1956

Poj 1273 Drainage Ditches(最大流 Edmonds-Karp )

题目链接:poj1273 Drainage Ditches 呜呜,今天自学网络流,看了EK算法,学的晕晕的,留个简单模板题来作纪念、、、 1 #include<cstdio> 2 #include<vector> 3 #include<queue> 4 #include<cstring> 5 #include&...

dhe56357的博客 161

STM32G4实战:用CubeMX+Keil五分钟搞定FreeRTOS多任务LED控制(避坑指南)

本文详细介绍了如何在STM32G4系列芯片上使用CubeMX和Keil快速配置FreeRTOS实现多任务LED控制,包括环境准备、时钟配置、任务创建及常见问题解决方案。重点解决了时钟源冲突等高频问题,并提供了优化建议和进阶应用示例,帮助开发者高效完成嵌入式开发任务。

joy55的博客 230

给IC设计新人的Tessent Scan入门指南:从RTL到ATPG的完整DFT流程解析

本文为IC设计新手提供Tessent Scan的完整DFT流程指南,从RTL代码检查到ATPG测试向量生成,详细解析扫描链配置、插入及验证的关键步骤。通过实战案例和工具命令示例,帮助工程师快速掌握Tessent工具链的应用技巧,提升芯片可测试性设计的效率和质量。

weixin_32541663的博客 459

HDU1532/POJ1273 Drainage Ditches 最大排水量 网络最大流 EK、Dinic、ISAP算法

题意:为了不让水淹三叶草,现在修了很多排水管,现在问从源点到汇点的最大排水量。

一蓑烟雨 1133

飞常准小程序接口逆向分析:如何破解航班查询的签名机制

本文深度解析了飞常准小程序航班查询接口的安全机制,重点剖析了其基于MD5和参数排序的签名算法。通过逆向分析核心代码,详细阐述了签名生成流程,并提供了Python实现的签名生成器与调试技巧,为开发者理解与模拟此类接口调用提供了实战指南。

zz67890的博客 541

POJ-1273 Drainage Ditches(最大流入门)

前述:这周周一做了两个组合数专题的题,依旧是容斥定理的题目,然后就不会了,正好专题延时了,就转向看了看网络流的博客,a了几道最大流的题,有简单的,有比较综合的,也只能不断摸索着前进,简单的构图还是可以想出来的,但是还是没理解拆点的意义所在,就是想不到为什么要拆点,也做了一些简单的尝试,就是把题解上拆点的做法,用不拆点的方法做,可是想法总觉得很好,就是总是wr,看起来我需要用脑子运行一下这个程序,才

m0_37772713的博客 240

渗透测试之哥斯拉实战

可以直接在这里使用meterpreter命令进行对服务端的控制。选择目标 - 添加,配置连接信息,之后测试连接成功!php的shell功能如图。先要进行数据库的配置信息。可以直接在这里打包全站。

大河之犬的博客 2500

深入理解Android音视频同步机制(三)NuPlayer的avsync逻辑

本文深入介绍了NuPlayer的avsync逻辑和原理

张晖的专栏 1万+

poj 1273 Drainage Ditches(最大流)

poj 1273 Drainage Ditches对增广路,最大流不知太熟悉,看这里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

总有那么一群人喜欢盯着我的博客看,估计这是他们见过最长的博客名,我必须得告诉他们博客名最长可以写多长 672

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

poj 1273 Drainage Ditches (最大流Dinic)

题目链接:   1273 题目大意:   有N个点和M条边,每条边最大的流量为c,初始流量为0                   1为源点,n为汇点求最大流 解题思路:  最短增广路算法比一般增广路算法每次增广大范围小,因为每次增广都在残留网络进行                   但是最短增广路每次还是要回到源点继续增广,而连续最短增广路算法则利用深搜的思想

ンZee的解题报告 1425

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

POJ1273 Drainage Ditches 【最大流Dinic】

Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 56870   Accepted: 21863 Description Every time it rains on Farmer John's fields, a pond fo

长风的专栏 988

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

POJ 1273 Drainage Ditches 最大流

Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 63802   Accepted: 24628 Description Every time it rains on Farmer John's fields, a pond form

阑珊记忆 429

POJ-1273 Drainage Ditches(最大流)

Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 71209   Accepted: 27705 Description Every time it rains on Farmer John's fields, a pond fo

十分残念的博客 2160

POJ-1273 Drainage Ditches【最大流】

题目链接:http://poj.org/problem?id=1273 题目大意: 有一个水塘,一个大海,要把水塘里的水尽可能多的排到大海里。当然,要通过一些水渠,这些水渠有一定的容量限制。 问最多能有多少水能流到大海里。 解题思路: 最大流的入门题。看了一上午就做了出来,很简单其实。。。用的BFS和Ford_Fulkerson算法。网上资料很多,大概看看应该就理解了。网络流开始还是很是

飘过的小牛 1547

POJ 1273 Drainage Ditches(最大流入门)

POJ 1273 Drainage Ditches(最大流入门) http://poj.org/problem?id=1273 题意:        现在有m个池塘(从1到m开始编号,1为源点,m为汇点),及n条有向水渠,给出这n条水渠所连接的点和所能流过的最大流量,求从源点到汇点能流过的最大流量。 分析:        裸的求1点到M点最大流的问题,直接用Dinic算法即可. AC代

code 1612

POJ 1273 Drainage Ditches(最大流模板)

题目链接:http://poj.org/problem?id=1273 题意:一些水管连接着十字路口,求从起点到终点的最大流量。 题解:基础模板题。注意重边。 代码: #include #include #include #include #include using namespace std; const int MAX=200+10; const int INF=0x3f3f3f3f

Keaper的博客 354

[POJ 1273] Drainage Ditches 最大流 模板题

题目传送门:【BZOJ 1273】 题目大意:Farmer John 担心他的三叶草被雨淋坏了,于是他修建了许多的排水沟将雨引到附近的一条小溪中。作为一名优秀的工程师,他有办法控制通过排水沟的水量。他不仅知道排水沟每分钟能运走多少水,还清楚它的详细结构。这些排水沟连接着一旁的池塘和小溪。现在,他想问你,这个排水沟将水从池塘引向小溪所允许的最大流量是多少。 输入多组数据,每组数据的第一行

江澤妮可 500

POJ 1273 Drainage Ditches 最大流

给你N条路径(有重边),和M个点,求以1为源点,M为汇点的最大流。

细语呢喃 1201

poj 1273 Drainage Ditches 网络最大流

很直白的网络最大流,我第一次好好做网络流,费整整一天呀!菜呀~~ 代码如下: #include #include using namespace std; const int Max=205; const int inf=99999999; int n,m,an

美文的ACM 623

POJ 1273Drainage Ditches(网络流之最大流)

题目地址:http://poj.org/problem?id=1273 网络流第一发!

scf0920 849

POJ-1273 Drainage Ditches 【最大流】

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...

137

【POJ 1273】Drainage Ditches网络流最大流模板

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, Fa...

Accelerato的博客 258

poj1273Drainage Ditches最大流[dinic算法]

这题太经典,可以作为所有最大流算法的入门题...所以昨天搞了好久dinic,愣是没明白建图那一步.后来干脆抛开那些代码,自己根据对dinic的理解写.没想到还能做出来! 好惊喜... 唉,也说说自己的感受吧,网上关于这方面的文章什么的太多了,而且各有各的理解,昨晚好痛苦,看了无数篇博客文章,总算理解到算法最关键的部分了.也给自己留个教训:别总想着模板,好习惯什么的,甚至还担心如果建图甚么的没做好

When you go away 1219
上一篇: 【数据结构】最短路径——Dijkstra算法
下一篇: POJ---3281 Dining【拆点最大流】
Acmer之家
博客等级 码龄10年 95粉丝 97原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值