Avoid The Lakes
Description Farmer John's farm was flooded in the most recent storm, a fact only aggravated by the information that his cows are deathly afraid of water. His insurance agency will only repay him, however, an amount depending on the size of the largest "lake" on his farm. Input * Line 1: Three space-separated integers: N, M, and K Output * Line 1: The number of cells that the largest lake contains. Sample Input 3 4 5 3 2 2 2 3 1 2 3 1 1 Sample Output 4 Source
题目大意:给你一块n*m的土地,上面有k块水坑,然后k行水坑的坐标,相邻前后左右的水坑能混合成一个大水坑,最大水坑有多大。
解题思路:深搜,将水坑的坐标标记,然后扫一遍图,如果扫到水坑的话进入搜索,将坑填平,每进入一次搜索,则填一次(大)坑,然后更新max。
代码如下:
|
POJ:3620 Avoid The Lakes(深搜DFS)
最新推荐文章于 2018-07-20 19:29:36 发布
本文介绍了一道经典的网格搜索问题“AvoidTheLakes”,通过深度优先搜索算法解决农场中最大湖泊面积的问题。该问题涉及网格地图上的水坑连接形成湖泊的概念,并详细展示了如何通过递归深度优先搜索来寻找并标记最大的湖泊。
摘要由CSDN通过智能技术生成