Last active
August 29, 2015 14:06
-
-
Save haroldxin/4feedb60f63d572b35b1 to your computer and use it in GitHub Desktop.
Lake Counting
This file contains hidden or 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
//POJ NO.2386 LAKE COUNTING | |
#include <iostream> | |
#include <cstdio> | |
using namespace std; | |
int N,M; | |
const int Max = 10000; | |
char field[Max][Max+1]; //園子 | |
void dfs(int x,int y){ | |
field[x][y]='.'; | |
for (int dx=-1;dx<=1;dx++){ | |
for(int dy=-1;dy<=1;dy++){ | |
int nx=x+dx;int ny=y+dy; | |
if(0<=nx && nx<N && 0<=ny && ny<M && field[nx][ny]=='W'){ | |
dfs(nx,ny); | |
} | |
} | |
} | |
return ; | |
} | |
void slove(){ | |
int res=0; | |
cin >> N; | |
cin >> M; | |
for (int i=0;i<N;i++){ | |
for (int j=1;j<M;j++){ | |
cin >> field[i][j]; | |
} | |
} | |
for(int i=0;i<N;i++){ | |
for (int j=0;j<M;j++){ | |
if(field[i][j]=='W'){ | |
dfs(i,j); | |
res++; | |
} | |
} | |
} | |
cout << res; | |
} | |
int main (){ | |
slove(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment