< >楼上的小弟们,其实这个题目用c语言编是可以实现的,并且运算量也不大,时间复杂度也就是n的2次幂。我编的这个程序可以求出40阶以内的任意阶魔方矩阵。程序在下面下载:</P>< ><a href="http://www.stuplaza.net/free/liuhao/magic.exe" target="_blank" >http://www.stuplaza.net/free/liuhao/magic.exe</A></P>< >求四的倍数阶的程序部分代码如下:</P><P><FONT color=#cc3333>{
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
k+=1;
m[j]=k;
if((int)(mod(x[j],4)/2.0)==(int)(mod(y[j],4)/2.0))
m[j]=n*n+1-m[j];
}
}</FONT></P><P><FONT color=#c43c3c>void meshgrid(int a[N][N],int b[N][N],int n)
{
int i,j;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
a[j]=j+1;
b[j]=i+1;
}
}
float mod(float f,int n)
{
int t,m;
t=(int)f/n;
if(f>0)
m=f-t*n;
else if((int)f%n==0)
m=t*n-f;
else
m=(-t+1)*n+f;
return m;
}</FONT></P> |