Accept: 140 Submit: 206
Time Limit: 1000 mSec Memory Limit : 32768 KB
Problem Description
The farm is represented as a rectangular grid with N (1<=N<=100) rows and M (1<=M<=100) columns. Each cell in the grid is either dry or submerged, and exactly K (1<=K<=N*M) of the cells are submerged. As one would expect, a lake has a central cell to which other cells connect by sharing a long edge (not a corner). Any cell that shares a long edge with the central cell or shares a long edge with any connected cell becomes a connected cell and is part of the lake.
Input
Each dataset contains two parts:
*Line 1: Three space-separated integers: N, M, and K.
*Lines 2..K+1: Line i+1 describes one submerged location with two space separated integers that are its row and column: R and C.
Input is terminated by end of file.
Output
For each dataset,you should output the number of cells that the largest lake contains.
Sample Input
Sample Output
Hint
Input Details:The farm is a grid with three rows and four columns; five of the cells are submerged. They are located in the positions (row 3, column 2); (row 2, column 2); (row 3, column 1); (row 2, column 3); (row 1, column 1):
# . . . . # # . # # ..
//一个很简单的深度优先搜索题; 但我看错了题目,把两个for循环里的n,m对掉了下, WA了3次....比窦娥冤还啊.....
.
本文介绍了一种使用深度优先搜索算法解决农场洪水模拟问题的方法,旨在计算由给定淹没位置形成的最大湖泊面积。该问题涉及在一个N*M的网格中找到最大的相连水域。
260

被折叠的 条评论
为什么被折叠?



