hdu2183

/*
分析:
    无聊找规律水题。。。
    自己找了个规律,弄出来一个n*n方阵,满足“排成n*n,方阵
每行每列每条对角线上的n个数字之和s相等”,但WA了,因为这题
不是special judge,必须按照这个题的那种规律才行。。。
    把1排在中心值下放,然后向右下递进,当next已经填过后,
让next_x=now_x+2,然后继续。。。


                                                    2012-11-12
*/








#include"stdio.h"
#include"string.h"
int num[25][25];
int main()
{
	int n;
	int i,l;
	int count;
	int now,now_x,now_y;
	int next,next_x,next_y;
	while(scanf("%d",&n),n)
	{
		count=n*n;
		memset(num,0,sizeof(num));
		next=1;
		next_x=n/2+2;
		next_y=n/2+1;
		while(count--)
		{
			now=next;
			now_x=next_x;
			now_y=next_y;
			num[now_x][now_y]=now;

			next=now+1;
			next_x=now_x+1;
			while(next_x>n)	next_x-=n;
			next_y=now_y+1;
			while(next_y>n)	next_y-=n;
			if(num[next_x][next_y])
			{
				next_x=now_x+2;
				while(next_x>n)	next_x-=n;
				next_y=now_y;
			}
		}

		for(i=1;i<=n;i++)
		{
			for(l=1;l<=n;l++)	printf("%4d",num[i][l]);
			printf("\n");
		}
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值