POJ 1273 Drainage Ditches (网络流 EK && Dinic)

拉曼光谱入门:10.显微拉曼与共聚焦技术 本文系统阐述了显微拉曼光谱技术与共聚焦原理的融合机制,详细解析了从激光激发、针孔空间滤波到光谱采集的完整光路架构,阐明了共聚焦设计在提升三维空间分辨率、抑制荧光背景及实现微区无损层析方面的核心优势,并探讨了关键光学器件的性能边界与系统技术局限。 阅读详情
Drainage Ditches
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 53153 Accepted: 20238

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


1、EK

思路:

       网络流EK算法入门模板题;

       资料 http://blog.sina.com.cn/s/blog_6cf509db0100uy5n.html


代码:

#include <stdio.h>
#include <string.h>
#include <queue>
#define INF 0xfffffff
#define N 220

using namespace std;

int map[N][N];
bool vis[N];			// bfs 时标记,避免走回路
int pre[N];				// 父节点

bool bfs(int start, int num)
{
	memset(pre, -1, sizeof(pre));		// 父节点初始化成-1
	memset(vis, 0, sizeof(vis));
	queue<int>q;

	pre[start] = start;					// 起点的父节点是本身
	vis[start] = 1;
	q.push(start);

	int cur;
	while(!q.empty()){
		cur = q.front();
		q.pop();

		for(int i = 1; i <= num; i ++){
			if(map[cur][i] > 0 && !vis[i]){		// 有关系,并且未曾访问
				pre[i] = cur;
				vis[i] = 1;
				if(i == num)					// 到达终点
					return 1;
				q.push(i);
			}
		}
	}

	return 0;
}

int EK(int start, int num)
{
	int ans = 0, min_w;
	while( bfs(start, num) ){
		min_w = INF;
		for(int i = num; i != start; i = pre[i]){				// 寻找最小边权,(逆向,找父节点)
			min_w = min_w < map[pre[i]][i] ? min_w : map[pre[i]][i];
		}

		for(int i = num; i != start; i = pre[i]){				// 更新边权,建立反向边
			map[pre[i]][i] -= min_w;
			map[i][pre[i]] += min_w;
		}
		ans += min_w;
	}

	return ans;
}

int main()
{
	int n, m;
	int start, end, p, ans;
	while(scanf("%d%d", &m, &n) != EOF){
		memset(map, 0, sizeof(map));

		for(int i = 0; i < m; i ++){
			scanf("%d%d%d", &start, &end, &p);
			map[start][end] += p;				// 注意,可能有重边
		}
		
		ans = EK(1, n);
		printf("%d\n", ans);
	}

	return 0;
}

2、Dinic

思路:

      bfs时每一步对原图进行分层,然后用DFS求增广路;

代码:

#include <stdio.h>
#include <string.h>
#include <queue>
#define INF 0x7fffffff
#define N 220
#define min(a, b) a < b ? a : b

using namespace std;

int level[N];				// 用于分层
int map[N][N];
int start, end;

bool bfs()
{
	queue<int>q;
	q.push(start);
	memset(level, 0, sizeof(level));
	level[start] = 1;
	
	int cur;
	while(!q.empty()){
		cur = q.front();
		q.pop();

		for(int i = 1; i <= end; i ++){
			if(!level[i] && map[cur][i] > 0){		// 条件:之前未被分层,并且两点有边权
				level[i] = level[cur] + 1;
				if(i == end){						// 到达终点
					return 1;
				}
				q.push(i);
			}
		}
	}
	
	return 0;
}

int dfs(int cur, int cp)
{
	if(cur == end)									// 到达终点
		return cp;									// 返回值是整条路径最小边权值

	int t, tmp = cp;
	for(int i = start; i <= end && tmp; i ++){
		if(level[i] == level[cur] + 1 && map[cur][i] > 0){		// 条件:两点之间层数相差1,并且两点之间有边权
			t = dfs(i, min(tmp, map[cur][i]));					// t接收此条路径最小边权值
			map[cur][i] -= t;						// 更新边权
			map[i][cur] += t;						// 建立反向边
			tmp -= t;
		}
	}

	return cp - tmp;
}

int Dinic()
{
	int ans = 0, min_w;
	while( bfs() ){							// 判断能否走通
		while( (min_w = dfs(start, INF)) ){			// 深搜整条路径
			ans += min_w;
		}
	}

	return ans;
}

int main()
{
	start = 1;
	int ct, x, y, p, ans;
	while(scanf("%d%d", &ct, &end) != EOF){
		memset(map, 0, sizeof(map));

		for(int i = 0; i < ct; i ++){
			scanf("%d%d%d", &x, &y, &p);
			map[x][y] += p;
		}

		ans = Dinic();
		printf("%d\n", ans);
	}

	return 0;
}


JAVA:Spring Boot 集成 Forest 优雅的 HTTP 客户端 Forest是一个优雅的Java HTTP客户端框架,通过注解式声明简化HTTP接口调用。它支持多HTTP客户端、自动参数绑定、序列化、重试机制和拦截器等功能。本文演示了如何在Spring Boot中集成Forest,包括配置、接口定义和调用示例,还展示了POST请求、文件上传等常见场景。相比传统HTTP客户端,Forest具有声明简洁、功能完善的特点,特别适合微服务调用和第三方API对接,能显著提升开发效率和代码可维护性。 阅读详情

相关推荐

SAP-PP 返工订单成本归集优化:从物料结算到成本中心的配置与增强实践

本文深入探讨SAP-PP模块中返工订单成本归集的优化方案,重点解析从物料结算到成本中心的配置与增强实践。通过结算参数文件配置、分配结构调整及增强开发实战,解决返工费用误计入物料成本的问题,确保财务核算精准性。文章还提供测试验证方案与常见报错处理技巧,助力企业实现成本数据清晰流向分析。

weixin_29260291的博客 364

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

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

一蓑烟雨 1131

不止是打字机效果:手把手教你用SpannableStringBuilder打造Android富文本AI对话界面

本文详细介绍了如何使用SpannableStringBuilder在Android平台上构建专业级AI对话界面,涵盖流式文本处理、富文本解析、交互优化等核心技术。通过实战代码示例,帮助开发者实现类似DeepSeek的AI产品交互效果,提升用户体验和应用专业度。

weixin_28358083的博客 198

Drainage Ditches [POJ - 1273] 【最大流模板_Dinic_EK】

POJ - 1273 Dinic算法 #include <iostream> #include <cstdio> #include <cstring> #include <queue> #define INF 0x3f3f3f3f using namespace std; inline int read() { int x = 0,...

L_X_ 205

深入MoveIt与OMPL集成开发:从源码编译到自定义规划算法实战

本文详细介绍了如何从源码编译集成MoveIt与OMPL,并实现自定义规划算法的完整流程。通过清理环境、获取源码、解决编译依赖与错误,最终指导开发者创建并集成名为MyRRT的自定义规划算法,从而实现对机器人运动规划栈的深度定制与优化。

h0i1j2k3l的博客 467

Computers & Security 投稿实战:从零到一详解避坑指南

本文详细解析了向《Computers & Security》投稿的全流程避坑指南,包括ORCID账号注册、文件格式统一、Editorial Manager®系统操作技巧等关键步骤。特别强调了cover letter撰写、Declaration of Interest Statement准备以及PDF生成后的检查要点,帮助研究者高效完成投稿流程。

weixin_29228203的博客 674

Drainage Ditches(POJ1273+网络流+Dinic+EK)

题目链接:poj.org/problem?id=1273 题目: 题意:求最大流。 思路:测板子题,分别用Dinic和EK实现(我的板子跑得时间均为0ms)。 Dinic代码实现如下: 1 #include <set> 2 #include <map> 3 #include <queue> 4 #includ...

di6499的博客 128

C#与Vector XL驱动库实战:CAN通道配置与端口访问详解

本文详细解析了使用C#调用Vector XL驱动库进行CAN总线通信开发的核心步骤。重点阐述了如何通过XL_GetDriverConfig获取硬件通道信息,并厘清channelMask与accessMask的区别与转换关系,最终指导开发者正确使用XL_OpenPort函数配置并打开CAN端口,为构建稳定的汽车电子测试与诊断应用奠定基础。

weixin_28452161的博客 362

POJ_1273 Drainage Ditches 【网络流】

一、题面   Drainage Ditches 二、分析   网络流的裸题。   1 Edmonds-Karp算法     求解网络流其实就是一个不断找增广路,然后每次找到一条增广路后更新残余网络的一个过程。     EK算法主要就是用bfs去找增广路,然后不断更新残余网络得到最终答案。   2 Dinic算法     对于Ford-Fulkerson和Edmonds-K...

weixin_30399155的博客 198

【GD32F407】i2c主机发送,从机中断接收

前言 现在手里负责的一个项目需要用i2c和主芯片进行通信主动发送,中断接收,这就需要支持i2c主机模式和从机模式,先查看原理图 这里我们用到了两条i2c总线进行数据的交替传输,避免在使用一条总线是发送数据和接收数据冲突 初始化i2c控制器 s32_k i2cDevInit(u8 byBusId, TI2cBus *pTI2cBus) { //PCLK = 36000000 BOOL retFlg = FALSE; int I2xSCL = pTI2cBus->byFastMode ?

Enosji的博客 6246

月薪2万+的网络工程师,到底藏着哪些“绝活”?

在IT圈,网络工程师是个既神秘又硬核的职业。月薪2万+的网工,早已不是只会拉网线、改IP的“IT民工”,而是掌握了一身“绝技”的技术大牛。他们能让企业网络如丝般顺滑,面对宕机临危不乱,还能用自动化脚本批量搞定上百台设备。想知道这些高薪网工的秘密武器是什么?今天,我就以一个老网工的视角,结合自己和同行们的实战经验,扒一扒那些月薪2万+的网络工程师都身怀哪些绝技。如果你也想挤进高薪行列,不妨参考参考!

网络技术联盟站 359

Drainage Ditches POJ1273

Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 93263 Accepted: 36174 试题链接 文章目录Description题意:题解:代码:Dinic做法EK做法 Description Every time it rains on Farmer John’s fields, a pond forms over Bessie’s favorite clover patch. This means that the clo

qq_35975367的博客 471

【WRF模拟】如何查看 WPS 的输入静态地理数据(二进制格式)?

如何查看 WPS 的输入静态地理数据(二进制格式)?

WW、forever的博客 633

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

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

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

POJ #1273 Drainage Ditches 网络流(最大流) 模板题 EK算法 Dinic算法

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

aibin6833的博客 176

WINCC7.3破解文件

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

【poj1273】Drainage Ditches(Dinic)

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 Be

Cabbage chicken的博客 472

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

POJ 1273 Drainage Ditches (最大流 :Dinic | EK)

Drainage Ditches Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submission(s) : 51   Accepted Submission(s) : 33 Problem Description Every time it rains on ...

weixin_34381666的博客 124

POJ 1273——Drainage Ditches【最大流 & EK算法 & Dinic算法 + 优化】

题目传送门 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 ...

NIRVANA REBIRTH 321

【POJ - 1273】Drainage Ditches(网络流,最大流,模板)

题干: 现在有m个池塘(从1到m开始编号,1为源点,m为汇点),及n条水渠,给出这n条水渠所连接的点和所能流过的最大流量,求从源点到汇点能流过的最大流量。 Input 输入包括几种情况。 对于每种情况,第一行包含两个空格分隔的整数,N(0 <= N <= 200)和M(2 <= M <= 200)。 N是Farmer John挖的沟渠数量。 M是那些沟渠的交叉点。 以...

xuanweiace的博客 581

[POJ1273][USACO4.2]Drainage Ditches (网络流最大流)

题意 网络流最大流模板 思路 EK也不会超时 所以说是一个数据比较水的模板题 但是POJ有点坑,多组数据,而且题目没给 哭得我AC率直掉 代码 用的朴素Dinic #include<cstdio> #include<algorithm> #include<cstring> #include<queue> ...

diejia6473的博客 174

Drainage Ditches(POJ-1273)(网络流—最大流)

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

菜鸡的博客 261

POJ1273 Drainage Ditches

EK, Dinic,预流推进,最高标号预留推进

H992109898的博客 802

POJ1273 Drainage Ditches(裸最大流,EK,DINIC)

注意重边。 EK: #include #include #include #define min(a,b) a<b?a:b using namespace std; const int N = 201; const int INF = 1000000000;

laoda扯一扯 878

poj1273 Drainage Ditches (最大流板子

网络流一直没学,来学一波网络流。 https://vjudge.net/problem/POJ-1273 题意:给定点数,边数,源点,汇点,每条边容量,求最大流。 解法:EK或dinic。 EK:每次增广用bfs选择一条从源到汇具有最少边数的增广路径,然后找出该路径容量最小的边,就是此次增加的流量,然后沿该路径增加反向边,同时修改每条边的容量,重复上述过程直到找不到增广路(即mi...

ddb21246的博客 160

poj 1273 Drainage Ditches 网络流 Edmond Karp || Dinic

// poj 1273 Drainage Ditches 网络流 Edmond Karp || Dinic // 题意: 裸的网络流,点数200,边数200 // 解答:经典的ff算法由于效率受容量限制,对于此题,容量可能大于10000000, // 所以采用EK算法,EK的效率是n*m*m,对于此题,可以在时限内解答. // Ford-Fulkerson:由残余网络出发,每次寻找流

TIMELIMITE的专栏 538

poj-1273 Drainage Ditches 最大流

/* http://poj.org/problem?id=1273 裸最大流 */ //EK算法 #include "stdio.h" #include "queue" using namespace std; const int maxn = 205; int map[maxn][maxn],path[maxn]; //邻接数组 前驱数组 int n,m; bool E

菜鸟成长ing 906
上一篇: POJ-1094 Sorting it all out (拓扑排序)
下一篇: nyoj-116 士兵杀敌(二)(树状数组插点问线-模板题)
tbl00c
博客等级 码龄13年 21粉丝 91原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值