Skip to content

Instantly share code, notes, and snippets.

@yamaguchi1024
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yamaguchi1024/cbfd381f0195ac4ec5b2 to your computer and use it in GitHub Desktop.
Save yamaguchi1024/cbfd381f0195ac4ec5b2 to your computer and use it in GitHub Desktop.
#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