1 条题解
-
0jacktang LV 8 @ 2017-10-27 21:06:01
#include<stdio.h>
#include<string.h>
int map[1005][1005];char line[1005];int tot;
int m,n;int max;
int dx[4][2]={{-1,0},{0,1},{1,0},{0,-1}};
int dy[4][2]={{0,1},{1,0},{0,-1},{-1,0}};struct node
{
int x,y;
int flag;
}s[1000000],tmp1,tmp2;int head=0,tail=0;
void push(node a)
{
s[++tail]=a;
}node pop()
{
return s[++head];
}void search(int i,int j)
{
tmp1.x=i;
tmp1.y=j;
tmp1.flag=0;
push(tmp1);
tot++;
head++;
for(register int k=0;k<=3;++k)
{
int biaoji=0;
while(1)
{
if(biaoji==0)
{
tmp1=s[1];
biaoji=1;
}
else
{
tmp1=pop();
}
tmp2.x=tmp1.x+dx[k][tmp1.flag];
tmp2.y=tmp1.y+dy[k][tmp1.flag];
if(map[tmp2.x][tmp2.y]!=1) break;
else
{
tot++;
if(tmp1.flag==0) tmp2.flag=1;
else tmp2.flag=0;
push(tmp2);
}
}
}
if(max<tot) max=tot;
}int main()
{
int t;
scanf("%d",&t);
for(register int nt=1;nt<=t;++nt)
{
memset(map,0,sizeof(map));
max=0;
scanf("%d%d",&n,&m);
for(register int i=1;i<=n;++i)
{
scanf("%s",line+1);
for(register int j=1;j<=m;++j)
{
map[i][j]=line[j]-48;
}
}
for(register int i=1;i<=n;++i)
{
for(register int j=1;j<=m;++j)
{
if(map[i][j]==0) continue;
tot=0;
head=0;tail=0;
search(i,j);
}
}
printf("%d\n",max);
}
return 0;
}
- 1