C++搜索与回溯算法之Lake Counting(数湖)
2017-07-02 17:36
357 查看
[align=center]Lake Counting(数湖)[/align]
('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')或干地('.')。农民约翰想知道在他的农场已经形成了多少个池塘。
一个池塘是一组连接在一起的水,一个包含水正方形被认为与其邻近的八个方向相邻。
给出了约翰农场的图表,确定他的农场里有多少池塘。
*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:两个空格分隔的整数:N和M
*行2..N + 1:每行代表一行农民约翰的字段的M个字符。
每个字符都是“W”或“.”。
字符之间没有空格。
翻译:
*行1:农民约翰的田野中的池塘数。
[align=center]Lake Counting(数湖)[/align]
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:两个空格分隔的整数:N和M
*行2..N + 1:每行代表一行农民约翰的字段的M个字符。
每个字符都是“W”或“.”。
字符之间没有空格。
Output(输出)
* Line 1: The number of ponds in Farmer John's field.翻译:
*行1:农民约翰的田野中的池塘数。
Sample Input(样例输入)
相关文章推荐
- C++搜索与回溯算法之The Castle
- [置顶] 信息学奥赛一本通(C++版) 第二部分 基础算法 第五章 搜索与回溯算法
- C++搜索与回溯算法之素数环问题
- C++搜索与回溯算法之马拦过河卒
- C++搜索与回溯算法之LETTERS(字母)
- C++搜索与回溯算法之棋盘问题
- C++搜索与回溯算法之选数
- C++搜索与回溯算法之全排列问题
- C++搜索与回溯算法之马走日(遍历问题)
- C++搜索与回溯算法之符号三角形
- C++搜索与回溯算法之拆数
- C++搜索与回溯算法之红与黑
- C++搜索与回溯算法之母亲的牛奶
- C++搜索与回溯算法之字符串全排列
- C++搜索与回溯算法之跳棋的挑战
- C++搜索与回溯算法之单词接龙
- C++搜索与回溯算法之八皇后问题
- 〖編程·C++〗回溯算法:排列树 - 工作分配问题
- C++数据结构--回溯算法--八皇后问题
- 浅谈种子搜索算法及C++实现方法