图在这里:
//算连块,没有碰到边缘的符合要求,此题放大三倍,算出来连块的格子数除以3就是结果
#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<stdlib.h>
#include<math.h>
int w,h,ok,sum,max,maze[500][500];
void dfs(int x,int y)
{
if(maze[x][y]) return ;
if(x==0||x==3*h-1||y==0||y==3*w-1){ok=1;return ;}
maze[x][y]=1;
sum++;
dfs(x-1,y);
dfs(x+1,y);
dfs(x,y-1);
dfs(x,y+1);
}
main()
{
int i,j,k,L,count=1,num;
char str[80];
//freopen("D:\\ppp.txt","r",stdin);
while(scanf("%d%d",&w,&h)&&w+h)
{
getchar();
max=num=0;
memset(maze,0,sizeof(maze));
for(i=0;i<h;i++)
{
gets(str);
L=strlen(str);
for(j=0;j<L;j++)
{
if(str[j]=='/')
{
for(k=3;k>0;k--)
maze[3*i+3-k][j*3+k-1]=1;
}
else
{
for(k=0;k<3;k++)
maze[3*i+k][3*j+k]=1;
}
}
}
for(i=0;i<h*3;i++)
{
for(j=0;j<w*3;j++)
{
ok=0;
if(maze[i][j]==0)
{
sum=0;
dfs(i,j);
if(ok==0)
{
num++;
if(sum>max)
max=sum;
}
}
}
}
if(max!=0)
printf("Maze #%d:\n%d Cycles; the longest has length %d.\n",count++,num,max/3);
else printf("Maze #%d:\nThere are no cycles.\n",count++);
printf("\n");
}
return 0;
}