Describe
Santa Claus has returned to the Arctic Christmas zone, which is almost 12 o ' notice. That means the Aurora show is going to start. The aurora borealis is not a polar-specific natural aurora borealis scene. But the man-made aurora that Santa Claus hosts.
Thundered...... Fireworks sounded (from China's Liuyang Fireworks township). Then there's the Aurora show.
The man-made Aurora is actually a dot-n*m image in the air. Just because it is particularly bright and attracts a lot of elf's eyes, but also become the most beautiful moment of Christmas Eve.
However, in each n*m bitmap image, each point has only two states: luminous and non-luminous. For all the glowing dots, a beautiful picture is formed in the air. And this picture is made up of several (s) patterns. For the pattern, Santa Claus has a strict definition: for the two illuminated points, if their Manhattan distance (for a (x1,y1) and B (X2,y2), A and b between the Manhattan distance of |x1-x2|+|y1-y2|) is less than or equal to 2. Then these two points belong to a pattern ...
While admiring the aurora, the elves counted the number of patterns in each aurora image. A beautiful Christmas night accompanied by singing and dancing. ^_^
Format input Format
The first line, two numbers n and M.
Next, there are N rows, with m characters per line. For the J-character of line I, if it is "-", then it indicates that the point does not glow, and if it is "#", then the point glows. Other characters cannot be present.
Output format
The first line, a number s.
Example 1 sample input 1[copy]
19---------------------------------------------------####- ----#-----#----------------------####-----######----#-----#---------------------######---########--#-#---#-#### #--#-##-##---#--########--###--###--#-#---#-#----#-##-##--#--#--###--###--###--###--#--#-#--######-#--#---#-#-- -###--###--########--#--#-#--#------#--#----##---########---######---#---#---######-#--#-----#----######-----## ##----------------------------#-----####-------------------------------------#--------------------------------- -------------------------------###--#--------#------#-------------------------#---#-#---------------#---------- --------------#------#-##--#-##--##-###-#-##-###--###-#--##---#------##--#-##-#-#----#--##--#---##---##-#-----# ------#---#-#--#--#---#--#---#---##----#--#-----#---#-#---#-#--#---#--#--#---#---##---##---#-----###--#---#-#-- #-##---#--#---#---#-###-#-##---------------------------------------------------
Sample output 1[Copy]
4
Limit
Each test point 1s
Solving
That is, a replica of the cell problem, note: The same cell is met in the following 12 directions
1 intdx[]={1,2,-1,-2,0,0,0,0,1,-1,1,-1};2 intdy[]={0,0,0,0,1,2,-1,-2,1,1,-1,-1};
Simply, the deep search code is as follows
#include <algorithm>#include<cstdio>#include<iostream>using namespacestd;intN,m,ans;intmap[101][101];Chara[101];intdx[]={1,2,-1,-2,0,0,0,0,1,-1,1,-1};intdy[]={0,0,0,0,1,2,-1,-2,1,1,-1,-1};intDfsintXinty) { for(intI=0;i< A; i++){ intpx=x+dx[i],py=y+Dy[i]; if(px<=n&&px>0&&py<=m&&py>0&&map[px][py]==0) {Map[px][py]=ans; DFS (PX,PY); } } }intPR () { for(intI=1; i<=n;i++){ for(intj=1; j<=m;j++) cout<<Map[i][j]; cout<<'\ n'; } cout<<'\ n';}intMain () {scanf ("%d%d",&n,&m); for(intI=1; i<=n;i++) {scanf ("%s", a); for(intj=0; j<m;j++) {map[i][j+1]= (a[j]=='-'); } } for(intI=1; i<=n;i++){ for(intj=1; j<=m;j++){ if(map[i][j]==0) {Map[i][j]=ans+1; Ans++; DFS (I,J);//PR ();} }} cout<<ans; return 0;}
"Vijos" p1051 to the aurora of Christmas Eve