1249:Lake Counting

Lake Counting

细胞 相比,不能说相似,只能说一模一样!(*╹▽╹*)

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<queue>
 4 using namespace std;
 5 
 6 const int N=1005;
 7 int r,c,ans,t[]={1,0,-1,-1,-1,0,1,1,-1,-1,-1,0,1,1,1,0};
 8 char a[N][N];
 9 queue<int> q;
10 void bfs(){
11     if(q.empty()){
12         ans++;
13         return;
14     }
15     int ni=q.front();
16     q.pop();
17     int nj=q.front();
18     q.pop();
19     a[ni][nj]='.';
20     for(int i=0;i<8;i++){
21         ni+=t[i],nj+=t[i+8];
22         if(ni>0&&ni<=r&&nj>0&&nj<=c&&a[ni][nj]=='W')
23             q.push(ni),q.push(nj);
24         ni-=t[i],nj-=t[i+8];
25     }
26     bfs();
27 }
28 int main(){
29     cin>>r>>c;
30     for(int i=1;i<=r;i++)
31         for(int j=1;j<=c;j++)
32             cin>>a[i][j];
33     for(int i=1;i<=r;i++)
34         for(int j=1;j<=c;j++)
35             if(a[i][j]=='W'){
36                 q.push(i),q.push(j);
37                 bfs();
38             }
39     cout<<ans;
40     return 0;
41 }

 

posted @ 2021-08-13 12:34  Rekord  阅读(349)  评论(0编辑  收藏  举报