#K37857. Honeycomb Clusters
Honeycomb Clusters
Honeycomb Clusters
You are given a honeycomb represented as a grid of R rows and C columns. Each cell in the grid is either '#' (representing a honey cell) or '.' (representing an empty cell). Two cells are considered connected if they share a common side (i.e., up, down, left, or right).
A honey cluster is defined as a group of connected '#' cells. Your task is to count the number of distinct honey clusters that contain more than one cell. Clusters consisting of a single cell should not be counted.
Formally, let the grid be represented as a matrix \( H \) of size \( R \times C \). Two cells \( H_{i,j} \) and \( H_{k,l} \) are adjacent if \(|i-k| + |j-l| = 1\). A cluster is a maximal set of cells where each cell is reachable from any other cell in the set via adjacent moves. Count only those clusters for which the size is \(\geq 2\).
inputFormat
The first line contains two integers, R and C (R, C ≥ 1), representing the number of rows and columns in the honeycomb.
The next R lines each contain a string of length C, consisting of the characters '#' and '.', representing the rows of the honeycomb.
outputFormat
Output a single integer which is the number of honey clusters that consist of more than one cell.
## sample4 5
.#..#
##..#
..###
.#...
2