[kuangbin带你飞]专题一 简单搜索 - L - Oil Deposits

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<algorithm>
 5 #include<queue>
 6 using namespace std;
 7 char g[105][105];
 8 int x, y, ans;
 9 int dx[3]={1,0,-1};
10 int dy[3]={1,0,-1};
11 bool sscanf()
12 {
13     char tmp[105];
14     scanf("%d%d",&x,&y);
15     if(x==0 && y==0)    return false;
16     for(int i = 1; i <= x; i++)
17     {
18         scanf("%s",tmp);
19         for(int j = 1; j <= y; j++)
20             g[i][j] = tmp[j-1];
21     }
22     ans = 0;
23     return true;
24 }
25 void find(int xi, int yi)
26 {
27     if(g[xi][yi]=='@')
28     {
29         g[xi][yi]='*';
30         for(int i = 0; i < 3; i++)
31             for(int j = 0; j < 3; j++)
32                 find(xi+dx[i],yi+dy[j]);
33     }
34     return;
35 }
36 int main()
37 {
38 //    freopen("in.in","r",stdin);
39 //    freopen("out.txt","w",stdout);
40     while(sscanf())
41     {
42         for(int i = 1; i <= x; i++)
43             for(int j = 1; j <= y; j++)
44             {
45                 if(g[i][j]=='@')
46                 {
47                     ans++;
48                     find(i, j);
49                 }
50             }
51         printf("%d\n",ans);    
52     }
53     
54     return 0;
55 }

 

posted @ 2015-01-29 20:32  天I火  阅读(302)  评论(0编辑  收藏  举报