
题意:求连通块个数。
分析:dfs。
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
typedef long long ll;
typedef unsigned long long llu;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const ll LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {, , -, , -, -, , };
const int dc[] = {-, , , , -, , -, };
const double pi = acos(-1.0);
const double eps = 1e-;
const int MAXN = + ;
const int MAXT = + ;
using namespace std;
int cnt;
int m, n;
int vis[MAXN][MAXN];
char a[MAXN][MAXN];
int judge(int i, int j){
return i >= && i < m && j >= && j < n;
}
void dfs(int x, int y){
vis[x][y] = ;
for(int i = ; i < ; ++i){
int tmpx = x + dr[i];
int tmpy = y + dc[i];
if(judge(tmpx, tmpy) && !vis[tmpx][tmpy] && a[tmpx][tmpy] == '@'){
dfs(tmpx, tmpy);
}
}
}
int main(){
while(scanf("%d%d", &m, &n) == ){
if(!m && !n) return ;
memset(vis, , sizeof vis);
cnt = ;
for(int i = ; i < m; ++i)
scanf("%s", a[i]);
for(int i = ; i < m; ++i){
for(int j = ; j < n; ++j){
if(a[i][j] == '@' && !vis[i][j]){
++cnt;
dfs(i, j);
}
}
}
printf("%d\n", cnt);
}
}