Drainage Ditches

hdu 1532 Drainage Ditches 基础最大流 最朴素的最大流 有向图 #include #include #include #include using namespace std; #define N 202 #define INF 1<<30 int g[N][N],n,m,pre[N]; int bfs() { queueq; while(!q.empty()) q.pop 阅读详情

题目:

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

 

题意:

 

给你n条边和m个点,问你1-m的网络最大流是多少?

 

思路:

裸的最大流问题,套用书上Edmonds-Karp算法即可。

 

代码:

#include<stdio.h>
#include<queue>
#include<string.h>
#include<vector>
#include<algorithm>
using namespace std;
const int maxn=250,inf=0x3f3f3f3f;
struct edge
{
    int from,to,cap,flow;
    edge(int u,int v,int c,int f):from(u),to(v),cap(c),flow(f) {}
};
struct EdmondsKarp
{
    int n,m;
    vector<edge>edges;
    vector<int>g[maxn];
    int a[maxn];
    int p[maxn];
    void init(int n)
    {
        for(int i=0; i<n; i++) g[i].clear();
        edges.clear();
    }
    void addedge(int from,int to,int cap)
    {
        edges.push_back(edge(from,to,cap,0));
        edges.push_back(edge(to,from,0,0));
        m=edges.size();
        g[from].push_back(m-2);
        g[to].push_back(m-1);
    }
    int Maxflow(int s,int t)
    {
        int flow=0;
        for(;;)
        {
            memset(a,0,sizeof(a));
            queue<int>q;
            q.push(s);
            a[s]=inf;
            while(!q.empty())
            {
                int x=q.front();
                q.pop();
                for(int i=0; i<(int)g[x].size(); i++)
                {
                    edge&e=edges[g[x][i]];
                    if(!a[e.to]&&e.cap>e.flow)
                    {
                        p[e.to]=g[x][i];
                        a[e.to]=min(a[x],e.cap-e.flow);
                        q.push(e.to);
                    }
                }
                if(a[t]) break;
            }
            if(!a[t]) break;
            for(int u=t; u!=s; u=edges[p[u]].from)
            {
                edges[p[u]].flow+=a[t];
                edges[p[u]^1].flow-=a[t];
            }
            flow+=a[t];
        }
        return flow;
    }
}EK;
int main()
{
    int n,m,a,b,c;
    while(scanf("%d%d",&n,&m)==2)
    {
        EK.init(m);
        for(int i=0; i<n; i++)
        {
            scanf("%d%d%d",&a,&b,&c);
            a--;
            b--;
            EK.addedge(a,b,c);
        }
        printf("%d\n",EK.Maxflow(0,m-1));
    }
    return 0;
}

 

即梦文生视频逆向接口部署使用 有的小伙伴不知道这个地址如何填写,你可以理解是步骤3上提供的 服务器或者本地电脑IP 地址(不要写 http://127.0.0.1 或者http://localhsot ) 是 (192.168.XXX.XXX 参考) 阅读详情

相关推荐

手把手教你用STM32单片机DIY一个简易PLC(附完整电路图与PCB文件)

本文详细介绍了如何利用STM32单片机DIY一个简易PLC控制器,涵盖硬件设计、电路图解析、PCB布局优化及固件框架实现。通过完整的电路图和PCB文件,帮助读者从元器件选型到工业级优化,逐步构建可靠的PLC系统,特别适合工业自动化爱好者和学习者实践。

weixin_42527160的博客 570

pku Drainage Ditches 简单最大流 直接套模板 注意可能有重边

#include<stdio.h>#include<string.h>#define MAX 201int m,n; //结点数int maxflow; //最大流int mat[MAX][MAX],pre[MAX],p[MAX];int queue[MAX*MAX];int min(int a,int b){ if(a<b) return a; e...

weixin_30871293的博客 84

关于keil编译报.sct (7): error: L6236E: No section matches selector - no section to be FIRST/LAST.处理方法

使用keilUvision5向下兼容,选择S3C2440主款芯片编译运行汇编语言。 出现了一个错误: . \objectslex3-2.sct (7): error: L6236E: No section matches selector - no section to be FIRST/LAST. 我在网上搜了很多,没有找到适合修正我这里的错误的。故咨询陈老师,终于将这个错误解决。 错误如下: 修改过程: 打开小仙女棒 将linker的Use Memory Layout fromTarget Dial

weixin_45865666的博客 9523

POJ-1273-Drainage Ditches

POJ-1273-Drainage Ditches http://poj.org/problem?id=1273 基本的最大流,Ford-Fulkerson算法,按LRJ的白书写的 #include&lt;iostream&gt; #include&lt;cstring&gt; #include&lt;queue&gt; using namespace std; #define INF ...

java开发指南博客 【转载】 144

黑五数据集实战:从消费者行为解码到零售智能决策

零售智能决策依赖对消费者行为的深度理解,其核心在于将结构化字段还原为真实商业动作。本文基于经典Black Friday数据集,系统阐释如何通过字段语义重定义、业务驱动的特征工程、轻量高效模型(如LightGBM)及定制化损失函数,构建可落地的库存预警、流失拦截与动线优化方案。重点融合‘消费人格指纹’与‘生态位稳定性分’两大热词,揭示数据背后的城市引力场、品类竞争网络与决策节奏图谱,为电商、快消及零售从业者提供从数据分析到业务闭环的完整方法论。

weixin_28630185的博客 345

VirtualBox增强功能安装全指南:从下载到配置复制粘贴功能

本文详细介绍了VirtualBox增强功能的完整安装与配置流程,重点解决了虚拟机与主机间复制粘贴、文件拖放等核心协作难题。通过分步指南和故障排查,帮助用户在不同操作系统(如Windows、Linux)中实现无缝集成,提升虚拟化工作效率与体验。

weixin_29206669的博客 418

最大流 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

搞定8GB/s数据流:一个FPGA工程师的XDMA驱动调优实战(附避坑清单)

本文详细记录了FPGA工程师在XDMA驱动调优过程中实现8GB/s高带宽数据流的实战经验。通过优化DDR访问、中断响应、DMA映射等关键环节,解决了PCIE数据采集卡在高带宽场景下的性能瓶颈,并提供了实用的避坑清单和技术方案。

weixin_29194255的博客 202

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

SPICE模型入门到精通

文章目录前言一、SPICE是什么?二、1. 前言 由于笔者的毕业设计与功率半导体器件建模相关,需要用到SPICE软件来建模,在这记录一下从零开始的SPICE学习历程~ 一、SPICE是什么? 电子产品的设计一般先从功能框图开始,然后细化到原理图,还要经过很调试验证过程,最终才能完成。调试和验证的过程复杂而繁琐,在设计集成电路时更是如此,在制造之前急需验证集成电路的功能。 根据电路理论,人们可以建立起节点方程和回路方程,通过解这些方程组成的方程组就可以得到结果,也就是说可以通过计算来获得电路的工作情况。但

qq_42031914的博客 7万+

基于自适应小波阈值算法的图像去噪

自适应小波阈值算法是一种基于小波变换的方法,它相对于传统的小波阈值去噪方法具有更好的性能和鲁棒性。该算法首先对图像进行小波变换,然后根据小波系数的大小确定一个自适应的阈值,将小波系数与阈值进行比较,大于阈值的系数被保留,小于阈值的系数被置零。在上述代码中,首先选取了小波函数sym4进行小波分解,然后根据标准差计算出阈值,使用wthresh函数进行阈值处理,最后进行反变换得到处理后的图像。该GUI界面与前面的自适应小波阈值算法代码结合,实现了图像的去噪,并提供了可视化的效果。

与其临渊羡鱼,不如退而结网 558

Hdu Drainage Ditches

View Code 1 /* 2 http://acm.hdu.edu.cn/webcontest/contest_showproblem.php?pid=1001&ojid=0&cid=4456&hide=0 3 4 hdu Drainage Ditches 5 */ 6 #include <iostream> ...

weixin_34113237的博客 1032

6、基因组数据可视化与甲基化分析:从基础操作到深入洞察

本文详细介绍了基因组数据可视化和全基因组DNA甲基化分析的方法和技术,包括基因组查看器(IGV)的基本操作、单核苷酸变异的可视化、DNA甲基化与CpG岛的关联分析、统计建模与显著甲基化区域识别,以及不同细胞系之间的甲基化模式差异分析。通过具体案例展示了如何利用MATLAB进行数据分析和可视化,为基因组研究、疾病机制探索及个性化医疗提供了技术支撑和实践参考。

qsc901234的博客 295

POJ 1273 Drainage Ditches

Drainage Ditches Time Limit:1000MS Memory Limit:10000K Total Submissions:67387 Accepted:26035 Description Every time it rains on Farmer John's fields,...

weixin_33883178的博客 73

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

【题解】Drainage Ditches HDU - 1532(最大流 模板题)⭐⭐

Drainage Ditches HDU - 1532 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 ...

Suprit's blog 629

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

HDU 1532 Drainage Ditches(最大流)

HDU 1532 Drainage Ditches 题目链接 最大流模板题 代码: #include #include #include #include using namespace std; const int MAXNODE = 205; const int MAXEDGE = 405; typedef int Type; const Type INF

Remilia's 666

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

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

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

m0_37772713的博客 239

HDU 1532 Drainage Ditches【HLPP网络流(最高标号预流推进)】

HDU 1532 Drainage Ditches 最大流裸题(同POJ 1273) 代码做了我所能理解的,比较详尽的注释。 参考教程:最大流算法-最高标号预流推进(HLPP)【PS:这大哥为了缩行,太可怕了QAQ】 #include<iostream> #include<cstring> #include<cstdio> #include<algor...

Irish_Moonshine的博客 504
上一篇: Slim Span
下一篇: Tree Recovery
admin__
博客等级 码龄8年 3粉丝 79原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值