C++搜索与回溯算法之Lake Counting(数湖)


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(样例输入)

发布了89 篇原创文章 · 获赞 120 · 访问量 14万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章