热门标签 | 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;
}




推荐阅读
  • Python处理Word文档的高效技巧
    本文详细介绍了如何使用Python处理Word文档,涵盖从基础操作到高级功能的各种技巧。我们将探讨如何生成文档、定义样式、提取表格数据以及处理超链接和图片等内容。 ... [详细]
  • 本文详细介绍如何在Linux系统中配置SSH密钥对,以实现从一台主机到另一台主机的无密码登录。内容涵盖密钥对生成、公钥分发及权限设置等关键步骤。 ... [详细]
  • MySQL DateTime 类型数据处理及.0 尾数去除方法
    本文介绍如何在 MySQL 中处理 DateTime 类型的数据,并解决获取数据时出现的.0尾数问题。同时,探讨了不同场景下的解决方案,确保数据格式的一致性和准确性。 ... [详细]
  • 在创建新的Android项目时,您可能会遇到aapt错误,提示无法打开libstdc++.so.6共享对象文件。本文将探讨该问题的原因及解决方案。 ... [详细]
  • 本文介绍如何使用 Android 的 Canvas 和 View 组件创建一个简单的绘图板应用程序,支持触摸绘画和保存图片功能。 ... [详细]
  • 目录一、salt-job管理#job存放数据目录#缓存时间设置#Others二、returns模块配置job数据入库#配置returns返回值信息#mysql安全设置#创建模块相关 ... [详细]
  • Qt QTableView 内嵌控件的实现方法
    本文详细介绍了在 Qt QTableView 中嵌入控件的多种方法,包括使用 QItemDelegate、setIndexWidget 和 setIndexWidget 结合布局管理器。每种方法都有其适用场景和优缺点。 ... [详细]
  • Coursera ML 机器学习
    2019独角兽企业重金招聘Python工程师标准线性回归算法计算过程CostFunction梯度下降算法多变量回归![选择特征](https:static.oschina.n ... [详细]
  • Nginx 反向代理与负载均衡实验
    本实验旨在通过配置 Nginx 实现反向代理和负载均衡,确保从北京本地代理服务器访问上海的 Web 服务器时,能够依次显示红、黄、绿三种颜色页面以验证负载均衡效果。 ... [详细]
  • 主板IO用W83627THG,用VC如何取得CPU温度,系统温度,CPU风扇转速,VBat的电压. ... [详细]
  • 给定一个整数数组arr,找到min(b)的总和,其中b的范围为arr的每个(连续)子数组。由于答案可能很大,因此返回答案模10^9+7。classSolution{publicin ... [详细]
  • 通过Web界面管理Linux日志的解决方案
    本指南介绍了一种利用rsyslog、MariaDB和LogAnalyzer搭建集中式日志管理平台的方法,使用户可以通过Web界面查看和分析Linux系统的日志记录。此方案不仅适用于服务器环境,还提供了详细的步骤来确保系统的稳定性和安全性。 ... [详细]
  • 不确定性|放入_华为机试题 HJ9提取不重复的整数
    不确定性|放入_华为机试题 HJ9提取不重复的整数 ... [详细]
  • 本文详细介绍了Java中的三大类设计模式:创建型模式、结构型模式和行为型模式,并探讨了设计模式遵循的六大原则,帮助开发者更好地理解和应用这些模式。 ... [详细]
  • 本文深入探讨了HTTP请求和响应对象的使用,详细介绍了如何通过响应对象向客户端发送数据、处理中文乱码问题以及常见的HTTP状态码。此外,还涵盖了文件下载、请求重定向、请求转发等高级功能。 ... [详细]
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社区 版权所有