xiaoguozi's Blog
Pay it forword - 我并不觉的自豪,我所尝试的事情都失败了······习惯原本生活的人不容易改变,就算现状很糟,他们也很难改变,在过程中,他们还是放弃了······他们一放弃,大家就都是输家······让爱传出去,很困难,也无法预料,人们需要更细心的观察别人,要随时注意才能保护别人,因为他们未必知道自己要什么·····

好久没写搜索题了,把以前的题写过的重新写了下
http://acm.hdu.edu.cn/showproblem.php?pid=1241

 1 #include <iostream>
 2 
 3 using namespace std;
 4 const int N=101;
 5 const int M=101;
 6 char mp[N][M];
 7 int dir[8][2]={1,0,-1,0,0,1,0,-1,1,1,1,-1,-1,-1,-1,1};
 8 int m,n;
 9 void Input()
10 {    
11     for(int i=0;i<m;i++)
12         for(int j=0;j<n;j++)
13             cin>>mp[i][j];
14 }
15 void dfs(int i,int j)
16 {
17     if(mp[i][j]=='@')mp[i][j]='*';
18     for(int r=0;r<8;r++){
19         int x=i+dir[r][0];
20         int y=j+dir[r][1];
21         if(x<0||y<0||x>=m||y>=n||mp[x][y]=='*')continue;
22         dfs(x,y);
23     }
24     return ;
25 }
26 int process()
27 {
28     int ans=0;
29     for(int i=0;i<m;i++){
30         for(int j=0;j<n;j++){
31             if(mp[i][j]=='@'){
32                 dfs(i,j);
33                 ++ans;
34             }
35         }
36     }
37     return ans;
38 }
39 int main()
40 {
41     while(cin>>m>>n,m+n){
42         Input();
43         cout<<process()<<endl;
44     }
45     return 0;
46 }
posted on 2008-07-21 11:46 小果子 阅读(425) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理