Last active
August 29, 2015 14:22
-
-
Save yamaguchi1024/cbfd381f0195ac4ec5b2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<cstdio> | |
#include<iostream> | |
using namespace std; | |
void dfs(int, int); | |
int n, m; | |
char a[200][200]; | |
int rain = 0; | |
int i, j, t, s; | |
int main(){ | |
scanf("%d", &n); | |
scanf("%d", &m); | |
for(i = 0; i <= n - 1; i++){ | |
for(j = 0; j <= m - 1; j++){ | |
scanf("%1c", &a[i][j]); | |
} | |
} | |
for(i=0; i <= n - 1; i++){ | |
for(j = 0; j <= m - 1; j++){ | |
if(a[i][j] == 'W'){ | |
dfs(i, j); | |
rain++; | |
} | |
} | |
} | |
/*for(i = 0; i <= n - 1; i++){ | |
for(j - 0; j <= m - 1; j++){ | |
if(a[i][j] == 'W') rain++; | |
} | |
} | |
*/ | |
printf("%d", rain); | |
return 0; | |
} | |
void dfs(int x, int y){ | |
for(t = -1; t <= 1 ; t++){ | |
for(s = -1; s <= 1; s++){ | |
/*if(s == 0 && t == 0){ | |
break; | |
}else{*/ | |
int dx = x + t; | |
int dy = y + s; | |
if(0 <= dx && dx <= n - 1 && 0 <= dy && dy <= m - 1 && a[dx][dy] == 'W'){ | |
a[dx][dy] == '.'; | |
dfs(dx, dy); | |
} | |
// } | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment