HDU4414 Finding crosses

 1 #include <iostream>

 2 #include <cstdio>

 3 #include <cstring>

 4 using namespace std;

 5 const int Ni = 60;

 6 bool vis[Ni][Ni];

 7 char map[Ni][Ni];

 8 int n;

 9 void Init()

10 {

11     memset(vis,0,sizeof(vis));

12     for(int i=0;i<n;i++)

13         scanf("%s",map[i]);

14 }

15 int pushdown(int i,int j)

16 {

17     int k;

18     for(k=0;i+k<n;k++)  if(map[i+k][j]=='#')

19         vis[i+1][j]=1;

20     else break;

21     return k;

22 }

23 int pushup(int i,int j)

24 {

25     int k;

26     for(k=0;i-k>=0;k++) if(map[i-k][j]=='#')

27         vis[i-k][j]=1;

28     else break;

29     return k;

30 }

31 int pushleft(int i,int j)

32 {

33     int k,flg=1;

34     for(k=0;j-k>=0;k++) if(map[i][j-k]=='#')

35     {

36         if(k&&(pushdown(i,j-k)!=1||pushup(i,j-k)!=1)) flg=0;

37         vis[i][j-k]=1;

38     }

39     else break;

40     if(flg) return k;

41     else return 0;

42 }

43 int pushright(int i,int j)

44 {

45     int k,flg=1;

46     for(k=0;j+k<n;k++) if(map[i][j+k]=='#')

47     {

48         if(k&&(pushdown(i,j+k)!=1||pushup(i,j+k)!=1)) flg=0;

49         vis[i][j+k]=1;

50     }

51     else break;

52     if(flg) return k;

53     else return 0;

54 }

55 bool ok(int i,int j)

56 {

57     int l,r,fd=1;

58     int d=pushdown(i,j);

59     if(!(d&1)||d==1) fd=0;

60     for(int k=0;k<d;k++)

61     {

62         l=pushleft(i+k,j)-1;

63         r=pushright(i+k,j)-1;

64         if(k==d/2)

65         {

66             if(l!=d/2||r!=d/2) fd=0;

67         }

68         else if(l!=0||r!=0)

69             fd=0;

70     }

71     return fd;

72 }

73 int finds()

74 {

75     int ans=0,i,j;

76     for(i=0;i<n;i++)

77     for(j=0;j<n;j++)

78     {

79        if(map[i][j]=='#'&&(!vis[i][j])&&ok(i,j)) ans++;

80     }

81     return ans;

82 }

83 int main()

84 {

85     while(scanf("%d",&n),n)

86     {

87         Init();

88         printf("%d\n",finds());

89     }

90     return 0;

91 }

 

 

你可能感兴趣的:(find)