uva705


图在这里:



//算连块,没有碰到边缘的符合要求,此题放大三倍,算出来连块的格子数除以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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值