【专家解说】:简单的搜索题,可以用DFS解决。以下是我的代码,LZ可以看一下: #include<iostream>
#include<cstring>using namespace std;const int N=105;char s[N][N];
bool map[N][N];
int d[8][2]={1,0,0,1,-1,0,0,-1,1,1,1,-1,-1,1,-1,-1};
int n,m;void dfs(int x,int y)
{
int i,tx,ty;
map[x][y]=false;
i=0;
while(i<8)
{
tx=x+d[i][0];
ty=y+d[i][1];
if(tx>=0&&ty>=0&&tx<n&&ty<m&&s[tx][ty]=='@'&&map[tx][ty])
dfs(tx,ty);
i++;
}
return;
}int main()
{
int i,j,ans;
while(scanf("%d%d",&n,&m)==2)
{
i=0;
while(i<n)
scanf("%s",s[i++]);
memset(map,true,sizeof(map));
ans=0;
i=0;
while(i<n)
{
j=0;
while(j<m)
{
if(s[i][j]=='@'&&map[i][j])
{
dfs(i,j);
ans++;
}
j++;
}
i++;
}
printf("%d\n",ans);
}
return 0;
}