#P8662. [蓝桥杯 2018 省 AB] 全球变暖

    ID: 7651 远端评测题 1000ms 256MiB 尝试: 0 已通过: 0 难度: 3 上传者: 标签>2018广度优先搜索,BFS蓝桥杯省赛

[蓝桥杯 2018 省 AB] 全球变暖

Description

You have a photo of a sea area with N×NN \times N pixels. . means ocean, and # means land, as shown below:

.......
.##....
.##....
....##.
..####.
...###.
.......

A piece of land connected in the four directions (up, down, left, right) forms an island. For example, the picture above has 22 islands.

Because global warming causes sea levels to rise, scientists predict that within the next few decades, the edge of each island, within a range of one pixel, will be submerged by seawater. Specifically, if a land pixel is adjacent to the ocean (among its four neighboring pixels in up, down, left, right, there is ocean), then it will be submerged.

For example, the sea area above will become the following in the future:

.......
.......
.......
.......
....#..
.......
.......

Please compute: according to the scientists' prediction, how many islands in the photo will be completely submerged.

Input Format

The first line contains an integer NN. (1N1000)(1 \le N \le 1000).

The following NN lines with NN characters per line represent a photo of the sea area.

The photo guarantees that the pixels in row 11, column 11, row NN, and column NN are all ocean.

Output Format

Output one integer representing the answer.

7 
.......
.##....
.##....
....##.
..####.
...###.
.......  
1

Hint

Time limit: 1 second, 256M. Lanqiao Cup, 9th Provincial Contest, 2018.

Translated by ChatGPT 5