标签:poj2386
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 20782 | Accepted: 10473 |
Description
Input
Output
Sample Input
10 12 W........WW. .WWW.....WWW ....WW...WW. .........WW. .........W.. ..W......W.. .W.W.....WW. W.W.W.....W. .W.W......W. ..W.......W.
Sample Output
3
Hint
Source
#include <stdio.h>
#include <string.h>
#define maxn 102
char G[maxn][maxn];
int n, m;
const int mov[][2] = {0, 1, 0, -1, 1, 0, -1,
0, 1, -1, -1, 1, 1, 1, -1, -1};
void DFS(int x, int y) {
G[x][y] = '.';
int i, j, nx, ny;
for(i = 0; i < 8; ++i) {
nx = x + mov[i][0];
ny = y + mov[i][1];
if(nx >= 0 && nx < n && ny >= 0 && ny < m && G[nx][ny] == 'W')
DFS(nx, ny);
}
}
int main() {
int i, j, ret;
while(scanf("%d%d", &n, &m) == 2) {
for(i = 0; i < n; ++i)
scanf("%s", G[i]);
ret = 0;
for(i = 0; i < n; ++i)
for(j = 0; j < m; ++j)
if(G[i][j] == 'W') {
DFS(i, j);
++ret;
}
printf("%d\n", ret);
}
return 0;
}标签:poj2386
原文地址:http://blog.csdn.net/chang_mu/article/details/40597237