Input/Output sample
Idea: See the topic I Meng first thought of certainly is to beg unicom fast, but this unicom fast a bit peculiar, because
So he is a unicom fast. There are three ways to solve the problem: 1) wide search (this conforms to the Basic Law), 2) and check set; 3) Irrigation method
But Konjac Konjac wrote and looked at the set.
The code is as follows:
1 varN,m,i,j,ans:longint;2C:Array[0.. +,0.. +] ofChar;3PreArray[0..10000000] ofLongint;4A:Array[0..10000000] ofBoolean;5 functionFind (X:longint): Longint;6 begin7 ifPre[x]=x Thenexit (x);8find:=find (Pre[x]);9pre[x]:=find;Ten End; One procedurejoin (x,y:longint); A varFx,fy:longint; - begin -Fx:=find (x); fy:=find (y); the ifFx<>fy Thenpre[fx]:=find (FY); - End; - begin - readln (n,m); + fori:=1 toN*m Dopre[i]:=i; - fori:=1 toN Do + begin A forj:=1 toM Do at begin - read (c[i,j]); - ifc[i,j]='#' Thena[(I-1) *m+j]:=true; - ifc[i,j]='-' Thena[(I-1) *m+j]:=false; - End; - Readln; in End; - fori:=1 toN Do to begin + forj:=1 toM Do - begin the ifc[i,j]='#' Then * begin $ ifc[i+1, j]='#' ThenJoin (I*m+j, (i-1) *m+j);Panax Notoginseng ifc[i,j+1]='#' ThenJoin ((I-1) *m+j+1, (I-1) *m+j); - ifc[i+2, j]='#' ThenJoin ((i+1) *m+j, (I-1) *m+j); the ifc[i,j+2]='#' ThenJoin ((I-1) *m+j+2, (I-1) *m+j); + ifc[i+1, J-1]='#' ThenJoin (i*m+j-1, (I-1) *m+j); A ifc[i+1, j+1]='#' ThenJoin (i*m+j+1, (I-1) *m+j);//In fact, not 12 points all to be sentenced again, because there are repeated coverage of the part the End; + End; - End; $ fori:=1 toN*m Do ifPre[i]=i Then ifA[i] ThenInc (ANS);//statistics "Unicom fast" number $ writeln (ans); - End.
View Code
This is Konjac Konjac first ac of mention, send an essay commemorative (^_^)
"Codevs" 1293