标签:which www cstring iostream field idt span print row
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 36946 | Accepted: 18370 |
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
简单深搜一下,就差不多了.
1 #include<iostream> 2 #include<cstring> 3 #include<cstdio> 4 #include<algorithm> 5 #define N 105 6 #define test cout<<"*****"<<endl 7 using namespace std; 8 char k[N][N]; 9 int n,m; 10 int dir[8][2]={{-1,-1},{-1,0},{-1,1},{0,1},{1,1},{1,0},{1,-1},{0,-1}}; 11 void dfs(int x,int y){ 12 k[x][y]=‘.‘; 13 for(int t=0;t<8;t++){ 14 int xx=x+dir[t][0]; 15 int yy=y+dir[t][1]; 16 if(xx>=0&&xx<n&&yy>=0&&yy<m&&k[xx][yy]==‘W‘) 17 dfs(xx,yy); 18 } 19 } 20 int main(){ 21 int cnt=0; 22 cin>>n>>m; 23 for(int i=0;i<n;i++){ 24 for(int j=0;j<m;j++){ 25 cin>>k[i][j]; 26 } 27 } 28 for(int i=0;i<n;i++) 29 for(int j=0;j<m;j++){ 30 if(k[i][j]==‘W‘){ 31 dfs(i,j); 32 cnt++; 33 } 34 } 35 printf("%d\n",cnt); 36 return 0; 37 }
标签:which www cstring iostream field idt span print row
原文地址:http://www.cnblogs.com/zllwxm123/p/7471413.html