标签:
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 24578 | Accepted: 12407 |
Description
Input
Output
Sample Input
10 12 W........WW. .WWW.....WWW ....WW...WW. .........WW. .........W.. ..W......W.. .W.W.....WW. W.W.W.....W. .W.W......W. ..W.......W.
Sample Output
3
Hint
Source
1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 #include<stack> 5 #include<set> 6 #include<map> 7 #include<queue> 8 #include<algorithm> 9 using namespace std; 10 char Map[105][105]; 11 int n,m; 12 void dfs(int x,int y){ 13 Map[x][y]=‘.‘; 14 int i,j; 15 for(i=-1;i<2;i++){ 16 int xx=x+i; 17 for(j=-1;j<2;j++){ 18 int yy=y+j; 19 if(xx>=0&&yy>=0&&xx<n&&yy<m&&Map[xx][yy]==‘W‘){ 20 dfs(xx,yy); 21 } 22 } 23 } 24 } 25 int main(){ 26 //freopen("D:\\INPUT.txt","r",stdin); 27 scanf("%d %d",&n,&m); 28 int i,j,k; 29 for(i=0;i<n;i++){ 30 scanf("%s",Map[i]); 31 } 32 int res=0; 33 for(i=0;i<n;i++){ 34 for(j=0;j<m;j++){ 35 if(Map[i][j]==‘W‘){ 36 dfs(i,j); 37 res++; 38 } 39 } 40 } 41 printf("%d\n",res); 42 return 0; 43 }
标签:
原文地址:http://www.cnblogs.com/Deribs4/p/4855058.html