pku3051 Satellite Photographs

http://poj.org/problem?id=3051

搜索,简单搜索

 1 #include <stdio.h>
 2 
 3 char map[1234][88];
 4 int n, m, dir[4][2] = {1,0, 0,1, -1,0, 0,-1};
 5 
 6 int dfs(int x, int y)
 7 {
 8     int sum = 1, i, p, q;
 9     for(i=0; i<4; i++)
10     {
11         p = x + dir[i][0];
12         q = y + dir[i][1];
13         if(map[p][q] == '*')
14         {
15             map[p][q] = '.';
16             sum += dfs(p, q);
17         }
18     }
19     return sum;
20 }
21 
22 int main()
23 {
24     int i, j, temp, result = 0;
25     scanf("%d%d%*c", &m, &n);
26     for(i=1; i<=n; i++)
27     {
28         scanf("%s%*c", &map[i][1]);
29     }
30     for(i=1; i<=n; i++)
31     {
32         for(j=1; j<=m; j++)
33         {
34             if(map[i][j] == '*')
35             {
36                 map[i][j] = '.';
37                 temp = dfs(i, j);
38                 if(temp > result)
39                 {
40                     result = temp;
41                 }
42             }
43         }
44     }
45     printf("%d\n", result);
46     return 0;
47 }

 

posted @ 2013-03-10 14:58  Yuan1991  阅读(123)  评论(0编辑  收藏  举报