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

POJ 2386

时间:2016-04-01 22:03:41      阅读:214      评论:0      收藏:0      [点我收藏+]

标签:

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

这个题目与那个POJ 1562几乎是差不多的,只不过那个比这个输入要复杂一些

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <iostream>
 4 
 5 
 6 using namespace std;
 7 
 8 char str[200][200];
 9 int dps(int i,int j)
10 {
11     if(str[i-1][j-1]==W)
12     {
13         str[i-1][j-1]=#;
14         dps(i-1,j-1);
15     }
16     if(str[i-1][j]==W)
17     {
18         str[i-1][j]=#;
19         dps(i-1,j);
20     }
21     if(str[i-1][j+1]==W)
22     {
23         str[i-1][j+1]=#;
24         dps(i-1,j+1);
25     }
26     if(str[i][j-1]==W)
27     {
28         str[i][j-1]=#;
29         dps(i,j-1);
30     }
31     if(str[i][j+1]==W)
32     {
33         str[i][j+1]=#;
34         dps(i,j+1);
35     }
36     if(str[i+1][j-1]==W)
37     {
38         str[i+1][j-1]=#;
39         dps(i+1,j-1);
40     }
41     if(str[i+1][j]==W)
42     {
43         str[i+1][j]=#;
44         dps(i+1,j);
45     }
46     if(str[i+1][j+1]==W)
47     {
48         str[i+1][j+1]=#;
49         dps(i+1,j+1);
50     }
51 
52 }
53 int main()
54 {
55     memset(str,0,sizeof(str));
56     int m,n,i,j,ans;
57     scanf("%d%d",&m,&n);
58     for(i=1;i<=m;i++)
59         scanf("%s",str[i]);
60     for(i=1,ans=0;i<=m;i++)
61         for(j=0;j<n;j++)
62         {
63             if(str[i][j]==W)
64             {
65                 ans++;
66                 str[i][j]=#;
67                 dps(i,j);
68             }
69         }
70     printf("%d",ans);
71     return 0;
72 }

 

POJ 2386

标签:

原文地址:http://www.cnblogs.com/Tree-dream/p/5346286.html

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