问题:
http://acm.pku.edu.cn/JudgeOnline/problem?id=1562思路:
简单的深度优先搜索,类似求连通域
1 void
2 dfs(int x, int y)
3 {
4 int i, sx, sy;
5 visited[x][y] = 1;
6 for(i=0; i<8; i++) {
7 sx = x+dx[i];
8 sy = y+dy[i];
9 if(within(sx, sy) && !visited[sx][sy] && map[sx][sy]=='@')
10 dfs(sx, sy);
11 }
12 }
13
14 void
15 solve()
16 {
17 int i, j;
18 for(i=0; i<m; i++)
19 for(j=0; j<n; j++)
20 if(map[i][j] == '@' && !visited[i][j]) {
21 dfs(i, j);
22 count+=1;
23 }
24 }