原题描述如下:
有一个大小为N*M的园子,雨后积水。八连通的积水被认为是连续在一起的。请求出园子里总共有多少水洼?(八连通指的是下图中相对w的*的部分)
***
*W*
***
(题目抄自《挑战程序设计竞赛》32页)
这个题目原文我看了几次都很懵逼。于是我又找了英文原版的表述
Due to recent rains, water has pooled in various places in Farmer John's field, which is represented by a rectangle of N x M (1 <= N <= 100; 1 <= M <= 100) squares. Each square contains either water ('W') or dry land ('.'). Farmer John would like to figure out how many ponds have formed in his field. A pond is a connected set of squares with water in them, where a square is considered adjacent to all eight of its neighbors. Given a diagram of Farmer John's field, determine how many ponds he has.
无妨,还是不懂,我寻思我英语也不差啊,也拿过大英赛和外研社的奖啊?
于是我又让chatgpt给我解释解释:
The problem you mentioned involves Farmer John's field, which is represented by a rectangle of squares. Each square can contain either water ('W') or dry land ('.'). The goal is to determine the number of ponds formed in the field.
A pond is defined as a connected set of squares with water in them. The squares are considered adjacent if they share a common side or corner. In other words, a square can have up to eight adjacent squares.
To solve the problem, you need to analyze the given diagram of Farmer John's field and identify the connected sets of water squares. Then, count the total number of these connected sets, which will give you the number of ponds in the field.
The dimensions of the field are given as N x M, where N represents the number of rows and M represents the number of columns. These dimensions will be within the range of 1 to 100.
I hope this explanation clarifies the problem for you. Let me know if you have any further questions!
得!还是不懂,我就直接看代码猜思路,才看出来门道。
意思就是找有几块被陆地(*)隔绝起来的水洼群(W)。水洼之间相邻(在对方的八角范围内)可以看成连接的群体。
一个水池(ponds)并不一定是中间一个W,周围八个*。中间的W可以有多个,可以是不规则的,而四周的*陆地只要能围住水就行了,边界也能看成陆地用来围。
这题的本质是找有几个连通区域。
这题目描述我正是服了。现在我学程序竞赛最卡人的就是这题目描述(哭)