#P1454. 圣诞夜的极光
圣诞夜的极光
Description
Santa Claus has returned to the Arctic Christmas Zone; it is almost 12 o'clock, which means the aurora show is about to begin. Here the aurora is not the natural polar lights but a man-made display directed by Santa.
Boom... fireworks go off (from Liuyang, the hometown of fireworks in China). Then comes the aurora show.
The man-made aurora is actually a series of dot-matrix images in the sky. Each point has only two states: lit or unlit. The lit points together form beautiful pictures. Each picture consists of several (exactly ) “patterns”. Santa defines a “pattern” strictly as follows: view lit points as vertices of a graph where two lit points are adjacent if their Manhattan distance is at most . For and , the Manhattan distance between and is . A “pattern” is a connected component of this graph. The elves watch the aurora and count the number of patterns in each image, singing and dancing through a beautiful Christmas night. ^_^
Input Format
The first line contains two integers and .
The next lines each contain characters. In the -th line, the -th character is - if the point is unlit, or # if the point is lit. No other characters appear.
Output Format
Output one integer on a single line.
19 48
------------------------------------------------
---####-----#-----#----------------------####---
--######----#-----#---------------------######--
-########--#-#---#-#####--#-##-##---#--########-
-###--###--#-#---#-#----#-##-##--#--#--###--###-
-###--###--#--#-#--######-#--#---#-#---###--###-
-########--#--#-#--#------#--#----##---########-
--######---#---#---######-#--#-----#----######--
---####----------------------------#-----####---
----------------------------------#-------------
------------------------------------------------
---###--#--------#------#-----------------------
--#---#-#---------------#-----------------------
-#------#-##--#-##--##-###-#-##-###--###-#--##--
-#------##--#-##-#-#----#--##--#---##---##-#----
-#------#---#-#--#--#---#--#---#---##----#--#---
--#---#-#---#-#--#---#--#--#---#---##---##---#--
---###--#---#-#--#-##---#--#---#---#-###-#-##---
------------------------------------------------
4
Hint
Constraints: .
Hint: DFS.
Translated by ChatGPT 5
京公网安备 11011102002149号