zju1002

#include <iostream>
#include <cstdio>
#include <queue>
#include <string.h>
using namespace std;
#define  size 5

typedef struct map
{
	char m[size][size];
	int ncastle;
}Map;

queue <Map> Q;

void inputsline(Map& a,int line,int x,int y)
{

	int newX=x;
	while (newX <= line  && a.m[newX][y] !='X')
	{
		a.m[newX++][y] ='S';
	}

	newX = x;
	while (newX>0 && a.m[newX][y] !='X')
	{
		a.m[newX--][y] ='S';

	}


	int newY= y;
	while (newY <= line  && a.m[x][newY] !='X')
	{
		a.m[x][newY++] ='S';
	}

	newY = y;
	while(newY>0  && a.m[x][newY]!='X')
	{
		a.m[x][newY--] ='S';
	}

}



int main()
{
	int nline;
	while(scanf("%d%*c",&nline),nline)
	{


		Map newMap; 
		memset(newMap.m,0,sizeof(newMap.m));


		int i ,j;
		//int ncastle;

		for(i = 1 ; i <= nline;i++)
			{
				for (j = 1 ; j <= nline ; j++)
				   scanf("%c",&newMap.m[i][j]);
		         getchar();
		}
		//   输入部分 	//

		newMap.ncastle = 0;

		Q.push(newMap);
		int maxcastle =0;
	
		while (!Q.empty())
		{
			Map newMap2 = Q.front();
			if(newMap2.ncastle>maxcastle) maxcastle = newMap2.ncastle;

			int flag_map = 0;
			//找到第一个未探测过 ,不是墙壁,
			for(i = 1; i <= nline;i++)
			{
				for(j = 1;j <= nline;j++)
				{
					if(newMap2.m[i][j] == 'X') continue;
					if(newMap2.m[i][j] == 'S') continue;
					if(newMap2.m[i][j] == '.')
					{
						/*****加入不放的*******
						*/
						
						//把该位置标记为已访问
                        
						newMap2.m[i][j] = 'S';
						Q.push(newMap2);

						/*****加入放的********
						 */

						inputsline(newMap2,nline,i,j);
						newMap2.ncastle++;
						
						Q.push(newMap2);


						flag_map =1;
			            break;
					}
					
				}
				if(flag_map)break;
			}
			Q.pop();
 		}
		printf("%d\n",maxcastle);
	}
	return 0;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值