POJ1273 Drainage Ditches

本文深入探讨了最大流问题,特别是解决Farmer John的排水沟问题,通过构建有向图并运用最大流算法来确定水从池塘流向溪流的最大速率。文章提供了详细的算法实现代码,包括初始化、边的添加、广度优先搜索和增广路径寻找等关键步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

一个有向图, M条有向边和N个点,求点1 到点N的最大流。

 

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.

第1行:2个整数M (2 <= M <= 200) 和N (0 <= N <= 200)。(注意给出的格式M N)

下来M行: 每行有三个整数:x,y,c。表示一条从点x到点y的有向边,流量为c (0<= c <= 10,000,000)。

 

Output

 

For each case, output a single integer, the maximum rate at which water may emptied from the pond.

输出一个整数,即最大流量。

 

Sample Input 1 

5 4
1 2 40
1 4 20
2 4 20
2 3 30
3 4 10

Sample Output 1

50

Source

 

最大流裸题,直接上板子。

  1 #include<bits/stdc++.h>
  2 using namespace std;
  3 
  4 const int maxn=100010;
  5 const int maxm=400010;
  6 const int inf=0x3f3f3f3f;
  7 struct Edge{
  8     int to,next,cap,flow,cost;
  9 }edge[maxm];
 10 
 11 int tol;
 12 int head[maxn];
 13 int gap[maxn],dep[maxn],cur[maxn];
 14 void init() {
 15     tol=0;
 16     memset(head,-1,sizeof(head));
 17 }
 18 void addedge(int u,int v,int w,int rw=0) {
 19     edge[tol].to=v;edge[tol].cap=w;edge[tol].flow=0;
 20     edge[tol].next=head[u];head[u]=tol++;
 21     edge[tol].to=u;edge[tol].cap=rw;edge[tol].flow=0;
 22     edge[tol].next=head[v];head[v]=tol++;
 23 }
 24 
 25 int Q[maxn];
 26 void bfs(int start,int end) {
 27     memset(dep,-1,sizeof(dep));
 28     memset(gap,0,sizeof(gap));
 29     gap[0]=1;
 30     int front=0,rear=0;
 31     dep[end]=0;
 32     Q[rear++]=end;
 33     while(front!=rear) {
 34         int u=Q[front++];
 35         for(int i=head[u];i!=-1;i=edge[i].next) {
 36             int v=edge[i].to;
 37             if(dep[v]!=-1) continue;
 38             Q[rear++]=v;
 39             dep[v]=dep[u]+1;
 40             gap[dep[v]]++;
 41         }
 42     }
 43 }
 44 
 45 int S[maxn];
 46 int sap(int start,int end,int n) {
 47     bfs(start,end);
 48     memcpy(cur,head,sizeof(head));
 49     int top=0;
 50     int u=start;
 51     int ans=0;
 52     while(dep[start]<n) {
 53         if(u==end) {
 54             int minn=inf;
 55             int inser;
 56             for(int i=0;i<top;i++) {
 57                 if(minn>edge[S[i]].cap-edge[S[i]].flow) {
 58                     minn=edge[S[i]].cap-edge[S[i]].flow;
 59                     inser=i;
 60                 }
 61             }
 62             for(int i=0;i<top;i++) {
 63                 edge[S[i]].flow+=minn;
 64                 edge[S[i]^1].flow-=minn;
 65             }
 66             ans+=minn;
 67             top=inser;
 68             u=edge[S[top]^1].to;
 69             continue;
 70         }
 71         bool flag=false;
 72         int v;
 73         for(int i=cur[u];i!=-1;i=edge[i].next) {
 74             v=edge[i].to;
 75             if(edge[i].cap-edge[i].flow&&dep[v]+1==dep[u]) {
 76                 flag=true;
 77                 cur[u]=i;
 78                 break;
 79             }
 80         }
 81         if(flag) {
 82             S[top++]=cur[u];
 83             u=v;
 84             continue;
 85         }
 86         int minn=n;
 87         for(int i=head[u];i!=-1;i=edge[i].next) {
 88             if(edge[i].cap-edge[i].flow&&dep[edge[i].to]<minn) {
 89                 minn=dep[edge[i].to];
 90                 cur[u]=i;
 91             }
 92         }
 93         gap[dep[u]]--;
 94         if(!gap[dep[u]]) return ans;
 95         dep[u]=minn+1;
 96         gap[dep[u]]++;
 97         if(u!=start) u=edge[S[--top]^1].to;
 98     }
 99     return ans;
100 }
101 
102 int main() {
103     int n,m;
104     while(~scanf("%d%d",&m,&n)) {
105         init();
106         for(int i=1;i<=m;i++) {
107             int u,v,w;
108             scanf("%d%d%d",&u,&v,&w);
109             addedge(u,v,w);
110         }
111         printf("%d\n",sap(1,n,n));
112     }
113 }

 

转载于:https://www.cnblogs.com/ACMerszl/p/10786258.html

标题基于SpringBoot+Vue的社区便民服务平台研究AI更换标题第1章引言介绍社区便民服务平台的研究背景、意义,以及基于SpringBoot+Vue技术的研究现状和创新点。1.1研究背景与意义分析社区便民服务的重要性,以及SpringBoot+Vue技术在平台建设中的优势。1.2国内外研究现状概述国内外在社区便民服务平台方面的发展现状。1.3研究方法与创新点阐述本文采用的研究方法和在SpringBoot+Vue技术应用上的创新之处。第2章相关理论介绍SpringBoot和Vue的相关理论基础,以及它们在社区便民服务平台中的应用。2.1SpringBoot技术概述解释SpringBoot的基本概念、特点及其在便民服务平台中的应用价值。2.2Vue技术概述阐述Vue的核心思想、技术特性及其在前端界面开发中的优势。2.3SpringBoot与Vue的整合应用探讨SpringBoot与Vue如何有效整合,以提升社区便民服务平台的性能。第3章平台需求分析与设计分析社区便民服务平台的需求,并基于SpringBoot+Vue技术进行平台设计。3.1需求分析明确平台需满足的功能需求和性能需求。3.2架构设计设计平台的整体架构,包括前后端分离、模块化设计等思想。3.3数据库设计根据平台需求设计合理的数据库结构,包括数据表、字段等。第4章平台实现与关键技术详细阐述基于SpringBoot+Vue的社区便民服务平台的实现过程及关键技术。4.1后端服务实现使用SpringBoot实现后端服务,包括用户管理、服务管理等核心功能。4.2前端界面实现采用Vue技术实现前端界面,提供友好的用户交互体验。4.3前后端交互技术探讨前后端数据交互的方式,如RESTful API、WebSocket等。第5章平台测试与优化对实现的社区便民服务平台进行全面测试,并针对问题进行优化。5.1测试环境与工具介绍测试
资源下载链接为: https://pan.quark.cn/s/9648a1f24758 Java中将Word文档转换为PDF是一种常见的技术需求,尤其在跨平台共享、保持格式一致性和便于在线预览等场景中非常实用。通常,开发者会借助专门的库来实现这一功能,其中Aspose.Words是一个非常强大的选择。Aspose.Words是由Aspose公司开发的文档处理组件,支持多种文件格式,包括Word和PDF。它提供了丰富的API,方便开发者在Java应用程序中进行文件转换、编辑和格式化操作,尤其在Word转PDF方面表现卓越。 使用Aspose.Words进行Word转PDF的步骤如下: 添加依赖:通过Maven或Gradle等工具将Aspose.Words的Java库引入项目。 加载Word文档:使用Document类加载Word文件,例如: 配置输出选项:创建PdfSaveOptions对象,用于设置PDF保存时的选项,如图像质量、安全性等。 执行转换:调用Document的save方法,传入输出路径和PdfSaveOptions对象,例如: 支持多种输出格式:Aspose.Words不仅支持将Word转换为PDF,还能转换为HTML、EPUB、XPS等多种格式,只需更换SaveOptions的子类即可。 保持格式与样式:在转换过程中,Aspose.Words能够最大程度地保留源文档的格式和样式,包括文本样式、图像位置、表格布局等。 优化性能:Aspose.Words支持并行处理和多线程技术,可以显著提高大量文档转换的速度。 处理复杂文档:它能够处理包含宏、复杂公式、图表、脚注等元素的Word文档,确保转换后的PDF内容完整且可读。 安全性与版权:在转换过程中,可以设置PDF的访问权限,例如禁止打印或复制文本,从而保护文档内容。 在实际开发中,还需要注意错误和异常的处理,以
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值