码迷,mamicode.com
首页 > 其他好文 > 详细

dfs/poj 2386 Lake Counting

时间:2014-11-15 20:10:40      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   color   ar   sp   for   div   on   

 1 #include<cstdio>
 2 using namespace std;
 3 const int b[8][2]={{-1,-1},{-1,0},{-1,1},{1,-1},{1,0},{1,1},{0,-1},{0,1}};
 4 int n,m;
 5 char a[110][110];
 6 
 7 void dfs(int x,int y)
 8 {
 9     a[x][y]=.;
10     for (int k=0;k<8;k++)
11     {
12         int dx=x+b[k][0];
13         int dy=y+b[k][1];
14         if (0<=dx && dx<n && 0<=dy && dy<m && a[dx][dy]==W) dfs(dx,dy);
15     }
16     return;
17 }
18 
19 int main()
20 {
21     scanf("%d%d",&n,&m);
22     for (int i=0;i<n;i++) scanf("%s",a[i]);
23 
24     int ans=0;
25     for (int i=0;i<n;i++)
26         for (int j=0;j<m;j++)
27             if (a[i][j]==W)
28             {
29                 dfs(i,j);
30                 ans++;
31             }
32     printf("%d\n",ans);
33     return 0;
34 }

 

dfs/poj 2386 Lake Counting

标签:style   blog   io   color   ar   sp   for   div   on   

原文地址:http://www.cnblogs.com/NicoleLam/p/4100065.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!