C++搜尋與回溯演算法之Lake Counting(數湖)

TOP-SECRET發表於2017-07-02

Lake Counting(數湖)

Description(描述)

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.

翻譯:

由於最近的降雨,水已經在農民約翰的農場中的各個地方聚集,這是由N×M(1 <= N <= 100; 1 <= M <= 100)正方形的矩形表示的。 每個正方形包含水('W')或乾地('.')。農民約翰想知道在他的農場已經形成了多少個池塘。 一個池塘是一組連線在一起的水,一個包含水正方形被認為與其鄰近的八個方向相鄰。
給出了約翰農場的圖表,確定他的農場裡有多少池塘。

Input(輸入)

* Line 1: Two space-separated integers: N and M

*Lines 2..N+1: M characters per line representing one row of Farmer John's field. Each character is either 'W' or '.'. The characters do not have spaces between them. 

翻譯:

*行1:兩個空格分隔的整數:NM

*行2..N + 1:
每行代表一行農民約翰的欄位的M個字元。 每個字元都是“W”或“.”。 字元之間沒有空格。

Output(輸出)

* Line 1: The number of ponds in Farmer John's field.

翻譯:

*行1:農民約翰的田野中的池塘數。

Sample Input(樣例輸入)

相關文章