Water problems, to find the number of connected components, deep search can be, the reason why this water is also written down, because the sample a set of wrong data I debugged for one hours, wasted a lot of energy and time. The last set of data has one more space after two 5:
I use GetChar to receive characters, so because it this reason more out of the space so that the characters are all chaotic, debugging output has a strange result, have to spit trough Hangzhou electric You too pit, although not the first time, before you put the row and column of the input order deliberately reverse, Now again here to leave a so disgusting pit, is it necessary to card these non-algorithmic and programming things?
1#include <cstdio>2#include <cstring>3 4 Chars[102][102];5 intdir[2][8]= {{-1,-1,-1,0,0,1,1,1},{-1,0,1,-1,1,-1,0,1}};6 7 voidDfsintIintj) {8 if(s[i][j]=='*')return ;9s[i][j]='*';Ten for(intk=0; k<8; ++k) { One intDi= i+dir[0][k], dj= j+dir[1][k]; A if(s[di][dj]=='@') DFS (DI,DJ); - } - } the - intMain () { - intn,m,i,j; - while(~SCANF ("%d%d",&n,&m), N) { + GetChar (); -memset (s),'*',sizeof(s)); + for(i=1; i<=n; ++I,getchar ()) A for(j=1; j<=m; ++j) ats[i][j]=GetChar (); - intans=0; - for(i=1; i<=n; ++i) - for(j=1; j<=m; ++j) - if(s[i][j]=='@'){ - DFS (I,J); in++ans; - } toprintf"%d\n", ans); + } - return 0; the}
Hdu 1241 Oil Deposits