标签:
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 22932 | Accepted: 11567 |
10 12
W........WW.
.WWW.....WWW
....WW...WW.
.........WW.
.........W..
..W......W..
.W.W.....WW.
W.W.W.....W.
.W.W......W.
..W.......W.
3
Hint
#include <iostream> #include <cstdio> #include <cstring> #define REP(i, s, n) for(int i = s; i <= n; i ++) #define REP_(i, s, n) for(int i = n; i >= s; i --) #define MAX_N 100 + 10 using namespace std; bool map[MAX_N][MAX_N]; int n, m, ans = 0; char ch; int dx[9] = {0, -1, -1, -1, 0, 0, 1, 1, 1}, dy[9] = {0, -1, 0, 1, -1, 1, -1, 0, 1}; void dfs(int x, int y){ REP(i, 1, 8){ if(x + dx[i] > 0 && x + dx[i] <= n && y + dy[i] > 0 && y + dy[i] <= m && map[x + dx[i]][y + dy[i]]) map[x + dx[i]][y + dy[i]] = 0, dfs(x + dx[i], y + dy[i]); } } int main(){ scanf("%d%d", &n, &m);getchar(); REP(i, 1, n){ REP(j, 1, m) scanf("%c", &ch), map[i][j] = (ch == ‘W‘ ? 1 : 0); getchar(); } REP(i, 1, n) REP(j, 1, m){ if(map[i][j]) dfs(i, j), ans ++; } printf("%d\n", ans); return 0; }
标签:
原文地址:http://www.cnblogs.com/ALXPCUN/p/4526407.html