求连通域个数,简单题
1 #include2 using namespace std; 3 const int INF = 0x3f3f3f3f; 4 typedef long long LL; 5 int n,m,ans=0; 6 char s[1001][1001]; 7 void dfs(int x,int y) 8 { 9 if(x<0||x>=n||y<0||y>=m||s[x][y]=='.')return;10 s[x][y]='.';11 dfs(x,y+1);12 dfs(x,y-1);13 dfs(x+1,y);14 dfs(x-1,y);15 dfs(x+1,y+1);16 dfs(x+1,y-1);17 dfs(x-1,y+1);18 dfs(x-1,y-1);19 }20 int main()21 {22 cin>>n>>m;23 for(int i=0;i