hdu 4414

1查找 #

       ###

         #

2 记a,b,c,d为距中心点的距离

3 如果a=b=c=d,在判断组成的cross的#号的上下左右没有#号

 

 

hdu 4414 View Code
  1 #include<iostream>

  2 #include<string>

  3 #include<stdio.h>

  4 using namespace std;

  5 int n;

  6 char map[60][60];

  7 int judge(int x,int y)

  8 {

  9     int a,b,c,d;

 10     int j;

 11     a=b=c=d=0;

 12     for(j=y-1;j>=1;j--)

 13     {

 14         if(map[x][j]=='o')

 15         {

 16             a=y-j-1;

 17             break;

 18         }

 19         if(j==1&&map[x][j]=='#')

 20         {

 21             a=y-1;

 22             break;

 23         }

 24         

 25     }

 26     for(j=y+1;j<=n;j++)

 27     {

 28         if(map[x][j]=='o')

 29         {

 30             b=j-y-1;

 31             break;

 32         }

 33         if(j==n&&map[x][j]=='#')

 34         {

 35             b=j-y;

 36             break;

 37         }

 38     }

 39     for(j=x-1;j>=1;j--)

 40     {

 41         if(map[j][y]=='o')

 42         {

 43             c=x-j-1;

 44             break;

 45         }

 46         if(j==1&&map[j][y]=='#')

 47         {

 48             c=x-1;

 49             break;

 50         }

 51     }

 52     for(j=x+1;j<=n;j++)

 53     {

 54         if(map[j][y]=='o')

 55         {

 56             d=j-x-1;

 57             break;

 58         }    

 59         if(j==n&&map[j][y]=='#')

 60         {

 61             d=j-x;

 62             break;

 63         }

 64     }

 65     

 66     int flag2=0;

 67     if(a==b&&b==c&&c==d)

 68     {

 69         int flag3=0;

 70         for(j=y-a;j<y;j++)

 71         {

 72             if(map[x-1][j]=='#'||map[x+1][j]=='#')

 73                 flag3=1;

 74         }

 75         for(j=y+1;j<=y+a;j++)

 76         {

 77             if(map[x-1][j]=='#'||map[x+1][j]=='#')

 78                 flag3=1;

 79         }

 80         for(j=x-a;j<x;j++)

 81         {

 82             if(map[j][y-1]=='#'||map[j][y+1]=='#')

 83                 flag3=1;

 84         }

 85         for(j=x+1;j<=x+a;j++)

 86         {

 87             if(map[j][y-1]=='#'||map[j][y+1]=='#')

 88                 flag3=1;

 89         }

 90         if(flag3==0)

 91             flag2=1;

 92     }

 93     if(flag2)

 94         return 1;

 95     else

 96         return 0;

 97 }

 98 int main()

 99 {

100     while(cin>>n)

101     {

102         if(!n)

103             break;

104         getchar();

105         int i,j;

106         for(i=1;i<=n;i++)

107         {

108             for(j=1;j<=n;j++)

109             {

110                 cin>>map[i][j];

111             }

112             getchar();

113         }

114         int count=0;

115         for(i=2;i<n;i++)

116         {

117             for(j=2;j<n;j++)

118             {

119                 if(map[i-1][j]=='#'&&map[i][j-1]=='#'&&map[i][j+1]=='#'&&map[i+1][j]=='#'&&map[i][j]=='#')

120                 {

121                     count+=judge(i,j);

122                 }

123                 

124             }

125         }

126         cout<<count<<endl;

127     }

128     return 0;

129     

130 }

 

你可能感兴趣的:(HDU)