热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

usaco4.2.1DrainageDitches

一原题DrainageDitchesHalBurchEverytimeitrainsonFarmerJohnsfields,apondformsoverBessiesfavorit

一 原题


Drainage Ditches
Hal Burch

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. Note however, that there can be more than one ditch between two intersections.

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.

PROGRAM NAME: ditch

INPUT FORMAT

Line 1:Two space-separated integers, N (0 <&#61; N <&#61; 200) and M (2 <&#61; M <&#61; 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.
Line 2..N&#43;1:Each of N lines contains three integers, Si, Ei, and Ci. Si and Ei (1 <&#61; Si, Ei <&#61; M) designate the intersections between which this ditch flows. Water will flow through this ditch from Si to Ei. Ci (0 <&#61; Ci <&#61; 10,000,000) is the maximum rate at which water will flow through the ditch.

SAMPLE INPUT (file ditch.in)

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

OUTPUT FORMAT

One line with a single integer, the maximum rate at which water may emptied from the pond.

SAMPLE OUTPUT (file ditch.out)

50






二 分析


裸最大流。因为那行应该注释掉的代码TLE了两次。。


三 代码


运行结果&#xff1a;

USER: Qi Shen [maxkibb3]
TASK: ditch
LANG: C&#43;&#43;Compiling...
Compile: OKExecuting...Test 1: TEST OK [0.000 secs, 4348 KB]Test 2: TEST OK [0.000 secs, 4348 KB]Test 3: TEST OK [0.000 secs, 4348 KB]Test 4: TEST OK [0.000 secs, 4348 KB]Test 5: TEST OK [0.000 secs, 4348 KB]Test 6: TEST OK [0.000 secs, 4348 KB]Test 7: TEST OK [0.000 secs, 4348 KB]Test 8: TEST OK [0.000 secs, 4348 KB]Test 9: TEST OK [0.000 secs, 4348 KB]Test 10: TEST OK [0.011 secs, 4348 KB]Test 11: TEST OK [0.000 secs, 4348 KB]Test 12: TEST OK [0.000 secs, 4348 KB]All tests OK.

Your program (&#39;ditch&#39;) produced all correct answers! This is your submission #3 for this problem. Congratulations!




AC代码&#xff1a;

/*
ID:maxkibb3
LANG:C&#43;&#43;
PROB:ditch
*/#includeconst int MAXV &#61; 205;
const int MAXC &#61; 1e7 &#43; 5;int m, n;
int c[MAXV][MAXV];
bool vis[MAXV];
int ans;int min(int a, int b) {return (a }void init() {scanf("%d%d", &m, &n);for(int i &#61; 0; i }int dfs(int idx, int flow) {if(idx &#61;&#61; n) return flow;for(int i &#61; 1; i <&#61; n; i&#43;&#43;) {if(vis[i]) continue;int f &#61; min(flow, c[idx][i]);if(f &#61;&#61; 0) continue;vis[i] &#61; true;int d &#61; dfs(i, f);//vis[i] &#61; false;if(d !&#61; 0) {c[idx][i] -&#61; d;c[i][idx] &#43;&#61; d;return d;}}return 0;
}void solve() {while(true) {for(int i &#61; 1; i <&#61; n; i&#43;&#43;) vis[i] &#61; false;vis[1] &#61; true;int delta &#61; dfs(1, MAXC);if(delta &#61;&#61; 0) break;ans &#43;&#61; delta;}printf("%d\n", ans);
}int main() {freopen("ditch.in", "r", stdin);freopen("ditch.out", "w", stdout);init(); solve();return 0;
}




推荐阅读
  • 本题探讨如何通过最大流算法解决农场排水系统的设计问题。题目要求计算从水源点到汇合点的最大水流速率,使用经典的EK(Edmonds-Karp)和Dinic算法进行求解。 ... [详细]
  • 本文深入探讨了 Java 中的 Serializable 接口,解释了其实现机制、用途及注意事项,帮助开发者更好地理解和使用序列化功能。 ... [详细]
  • 本文将介绍如何编写一些有趣的VBScript脚本,这些脚本可以在朋友之间进行无害的恶作剧。通过简单的代码示例,帮助您了解VBScript的基本语法和功能。 ... [详细]
  • UNP 第9章:主机名与地址转换
    本章探讨了用于在主机名和数值地址之间进行转换的函数,如gethostbyname和gethostbyaddr。此外,还介绍了getservbyname和getservbyport函数,用于在服务器名和端口号之间进行转换。 ... [详细]
  • 本文介绍如何使用阿里云的fastjson库解析包含时间戳、IP地址和参数等信息的JSON格式文本,并进行数据处理和保存。 ... [详细]
  • 尽管使用TensorFlow和PyTorch等成熟框架可以显著降低实现递归神经网络(RNN)的门槛,但对于初学者来说,理解其底层原理至关重要。本文将引导您使用NumPy从头构建一个用于自然语言处理(NLP)的RNN模型。 ... [详细]
  • 实体映射最强工具类:MapStruct真香 ... [详细]
  • 不确定性|放入_华为机试题 HJ9提取不重复的整数
    不确定性|放入_华为机试题 HJ9提取不重复的整数 ... [详细]
  • 本文探讨了Hive中内部表和外部表的区别及其在HDFS上的路径映射,详细解释了两者的创建、加载及删除操作,并提供了查看表详细信息的方法。通过对比这两种表类型,帮助读者理解如何更好地管理和保护数据。 ... [详细]
  • 主要用了2个类来实现的,话不多说,直接看运行结果,然后在奉上源代码1.Index.javaimportjava.awt.Color;im ... [详细]
  • DNN Community 和 Professional 版本的主要差异
    本文详细解析了 DotNetNuke (DNN) 的两种主要版本:Community 和 Professional。通过对比两者的功能和附加组件,帮助用户选择最适合其需求的版本。 ... [详细]
  • ImmutableX Poised to Pioneer Web3 Gaming Revolution
    ImmutableX is set to spearhead the evolution of Web3 gaming, with its innovative technologies and strategic partnerships driving significant advancements in the industry. ... [详细]
  • 本章将深入探讨移动 UI 设计的核心原则,帮助开发者构建简洁、高效且用户友好的界面。通过学习设计规则和用户体验优化技巧,您将能够创建出既美观又实用的移动应用。 ... [详细]
  • dotnet 通过 Elmish.WPF 使用 F# 编写 WPF 应用
    本文来安利大家一个有趣而且强大的库,通过F#和C#混合编程编写WPF应用,可以在WPF中使用到F#强大的数据处理能力在GitHub上完全开源Elmis ... [详细]
  • 本文详细介绍了Java中的输入输出(IO)流,包括其基本概念、分类及应用。IO流是用于在程序和外部资源之间传输数据的一套API。根据数据流动的方向,可以分为输入流(从外部流向程序)和输出流(从程序流向外部)。此外,还涵盖了字节流和字符流的区别及其具体实现。 ... [详细]
author-avatar
伤心的海2012_626
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有