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




推荐阅读
  • 题目描述Takuru是一名情报强者,所以他想利用他强大的情报搜集能力来当中间商赚差价。Takuru的计划是让Hinae帮他去市场上买一个商品,然后再以另一个价格卖掉它。Takur ... [详细]
  • 本文介绍了在Cpp中将字符串形式的数值转换为int或float等数值类型的方法,主要使用了strtol、strtod和strtoul函数。这些函数可以将以null结尾的字符串转换为long int、double或unsigned long类型的数值,且支持任意进制的字符串转换。相比之下,atoi函数只能转换十进制数值且没有错误返回。 ... [详细]
  • DescriptionclickmeSolution套路的状压期望DP题。。。考虑倒退期望:设fi,jrolepresentationstyleposi ... [详细]
  • 开发笔记:城市建设
    本文由编程笔记#小编为大家整理,主要介绍了城市建设相关的知识,希望对你有一定的参考价值。本文涉及:cdq分治、MST一道十分精妙的cdq分 ... [详细]
  • Java序列化对象传给PHP的方法及原理解析
    本文介绍了Java序列化对象传给PHP的方法及原理,包括Java对象传递的方式、序列化的方式、PHP中的序列化用法介绍、Java是否能反序列化PHP的数据、Java序列化的原理以及解决Java序列化中的问题。同时还解释了序列化的概念和作用,以及代码执行序列化所需要的权限。最后指出,序列化会将对象实例的所有字段都进行序列化,使得数据能够被表示为实例的序列化数据,但只有能够解释该格式的代码才能够确定数据的内容。 ... [详细]
  • 本文主要解析了Open judge C16H问题中涉及到的Magical Balls的快速幂和逆元算法,并给出了问题的解析和解决方法。详细介绍了问题的背景和规则,并给出了相应的算法解析和实现步骤。通过本文的解析,读者可以更好地理解和解决Open judge C16H问题中的Magical Balls部分。 ... [详细]
  • 本文讨论了使用差分约束系统求解House Man跳跃问题的思路与方法。给定一组不同高度,要求从最低点跳跃到最高点,每次跳跃的距离不超过D,并且不能改变给定的顺序。通过建立差分约束系统,将问题转化为图的建立和查询距离的问题。文章详细介绍了建立约束条件的方法,并使用SPFA算法判环并输出结果。同时还讨论了建边方向和跳跃顺序的关系。 ... [详细]
  • 本文介绍了P1651题目的描述和要求,以及计算能搭建的塔的最大高度的方法。通过动态规划和状压技术,将问题转化为求解差值的问题,并定义了相应的状态。最终得出了计算最大高度的解法。 ... [详细]
  • 本文介绍了UVALive6575题目Odd and Even Zeroes的解法,使用了数位dp和找规律的方法。阶乘的定义和性质被介绍,并给出了一些例子。其中,部分阶乘的尾零个数为奇数,部分为偶数。 ... [详细]
  • 本文介绍了一个题目的解法,通过二分答案来解决问题,但困难在于如何进行检查。文章提供了一种逃逸方式,通过移动最慢的宿管来锁门时跑到更居中的位置,从而使所有合格的寝室都居中。文章还提到可以分开判断两边的情况,并使用前缀和的方式来求出在任意时刻能够到达宿管即将锁门的寝室的人数。最后,文章提到可以改成O(n)的直接枚举来解决问题。 ... [详细]
  • 本文讨论了一个数列求和问题,该数列按照一定规律生成。通过观察数列的规律,我们可以得出求解该问题的算法。具体算法为计算前n项i*f[i]的和,其中f[i]表示数列中有i个数字。根据参考的思路,我们可以将算法的时间复杂度控制在O(n),即计算到5e5即可满足1e9的要求。 ... [详细]
  • 本文介绍了关于Java异常的八大常见问题,包括异常管理的最佳做法、在try块中定义的变量不能用于catch或finally的原因以及为什么Double.parseDouble(null)和Integer.parseInt(null)会抛出不同的异常。同时指出这些问题是由于不同的开发人员开发所导致的,不值得过多思考。 ... [详细]
  • 796.[APIO2012]派遣在一个忍者的帮派里,一些忍者们被选中派遣给顾客,然后依据自己的工作获取报偿。在这个帮派里,有一名忍者被称之为Master。 ... [详细]
  • P2765魔术球问题这道题的思路实在是太罕见了,所以发一篇blog从某一新放入的球开始看起1.放入原来的柱子上2.放入新的柱子并将每个点进行拆点࿰ ... [详细]
  • JZOJ 1266. 玉米田
    1266.玉米田(cowfood.pasccpp)(FileIO):input:cowfood.inoutput:cowfood.outTimeLimits:1000msMemor ... [详细]
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社区 版权所有