不是一般的水。。。。。。
AC代码如下:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
typedef struct{
int x, y;
}Node;
int map[100][100];
int N, M;
bool mark[100][100];
int sum;
int moves[8][2] = { 1, 0, -1, 0, 0, 1, 0, -1, -1, -1, -1, 1, 1, -1, 1, 1 };
void BFS(){
for( int i = 0; i < N; i++ ){
for( int j = 0; j < M; j++ ){
if( mark[i][j] == true || map[i][j] == 0 ){
continue;
}
Node start;
start.x = i;
start.y = j;
sum++;
mark[start.x][start.y] = true;
queue<Node> q;
q.push( start );
while( !q.empty() ){
Node n = q.front();
q.pop();
for( int l = 0; l < 8; l++ ){
Node temp = n;
temp.x += moves[l][0];
temp.y += moves[l][1];
if( mark[temp.x][temp.y] ){
continue;
}
if( map[temp.x][temp.y] == 0 ){
continue;
}
if( temp.x < 0 || temp.x >= N || temp.y < 0 || temp.y >= M ){
continue;
}
mark[temp.x][temp.y] = true;
q.push( temp );
}
}
}
}
}
int main(){
char s[101];
while( cin >> N >> M && !( N == 0 && M == 0 ) ){
for( int i = 0; i < N; i++ ){
scanf( "%s", s );
for( int j = 0; j < M; j++ ){
if( s[j] == '@' ){
map[i][j] = 1;
}else{
map[i][j] = 0;
}
}
}
memset( mark, false, sizeof(mark) );
sum = 0;
BFS();
cout << sum << endl;
}
return 0;
}