#STSC1B. [STSC OI - 1B] 城墙 (walls)
[STSC OI - 1B] 城墙 (walls)
Description
In the ruins, traces of war remain, along with scattered remnants of walls and towers. These structures were once connected, but the war has fragmented them.
To restore them, we first need to determine how many sections the walls are divided into. Here, walls and towers are considered as one entity. Given a map, your task is to calculate how many separate sections the wall is divided into.
Input
Line : Two positive integers , indicating the map has rows and columns.
Line : Input a -row by -column map consisting only of the characters # and .. # represents walls or towers, while . represents empty space.
Structures shaped like the following are considered a single connected section:
#.
.#
Output
Output a natural number , representing the number of sections the wall is divided into.
4 5
#...#
##..#
...#.
#....
3
Hint
For of the data, .
【Sample #1 Explanation】
The map contains three sections:
- Top-left section:
#.
##
- Top-right section:
.#
.#
#.
- Bottom-left section:
#
相关
在以下作业中: