这是2012网络赛的一道题目,去年网络赛做的非常不好,于是现在就想翻翻这题目,耐住心好好做一下,本想下午完成这道题目来,一直拖到了现在。 注意条件必须是奇数个,两边的长度都相等,既然是奇数个就会有中心,每条边都要过另一条边的中心,很容易就会知道他的形态。 注意他的数据中好像是有空格,害怕这种情况的发生直接用gets处理。总不会出错吧。
#include
#include
#include
int a[100][100];
char s1[1000000];
struct num
{
int x,y;
}hor[100],ver[100];
int main()
{
int i,j,n,m,s,t,k,res,pre,next,top1,top2,zhong,x,u;
int xend,yend,l;
char c;
while(scanf("%d",&n)!=EOF)
{
if(!n)
{
break;
}
gets(s1);
for(i=0;i<=n-1;i++)
{
gets(s1);
l=strlen(s1);
for(j=0,x=0;j<=l-1;j++)
{
if(s1[j]=='o')
{
a[i][x]=0; x++;
}else if(s1[j]=='#')
{
a[i][x]=1; x++;
}
}
a[i][n]=0;
}
res=0;
for(i=1;i<=n-1;i++)
{
for(j=0,k=0,top1=top2=0;j<=n;j++)
{
if(a[i][j]==1&&k==0)
{
hor[top1].x=i;
hor[top1++].y=j;
pre=next=j;
k=1;
}else if(a[i][j]==1&&k==1)
{
next+=1;
hor[top1].x=i;
hor[top1++].y=j;
}else if(!a[i][j])
{
if(k==1&&top1>=3&&top1%2)
{
zhong=(next+pre)/2;
for(x=i-1;x>=0;x--)
{
if(a[x][zhong])
{
ver[top2].x=x;
ver[top2++].y=zhong;
}else
{
break;
}
}
if(top2==top1/2)
{
for(x=i+1;x<=n-1;x++)
{
if(a[x][zhong])
{
ver[top2].x=x;
ver[top2++].y=zhong;
}else
{
break;
}
}
if(top2==top1-1)
{
for(u=0;u<=top1-1; u++)
{
xend=hor[u].x;
yend=hor[u].y;
if(xend==i&¥d==zhong)
{
continue;
}
if(xend-1>=0)
{
if(a[xend-1][yend])
{
break;
}
}
if(xend+1<=n-1)
{
if(a[xend+1][yend])
{
break;
}
}
}
if(u==top1)
{
for(u=0;u<=top2-1;u++)
{
xend=ver[u].x;
yend=ver[u].y;
if(yend-1>=0)
{
if(a[xend][yend-1])
{
break;
}
}
if(yend+1<=n)
{
if(a[xend][yend+1])
{
break;
}
}
}
if(u==top2)
{
res++;
}
}
}
}
}
k=0; top1=top2=0;
}
}
}
printf("%d\n",res);
}
return 0;
}