马的遍历
2008-03-08 12:26:36 来源:WEB开发网核心提示:由于算法不是很好,要等几分钟才能出结果,马的遍历,#include<stdio.h>int a[8][8]=;void f(int x,int y){int m,n,i;if(k==65){PRintf(" ");for(a1=0;a1<8;a1++) {for(a2=0;a2
由于算法不是很好,要等几分钟才能出结果。
#include<stdio.h>
int a[8][8]=;
void f(int x,int y)
{int m,n,i;
if(k==65){PRintf(" ");
for(a1=0;a1<8;a1++)
{for(a2=0;a2<8;a2++)
printf("%3d",a[a1][a2]);
printf(" "); } }
else
for(i=1;i<64;i++)
{m=i/8;n=i%8;
if(((n-x)*(n-x)+(m-y)*(m-y))==5&&a[n][m]==0)
{ a[n][m]=k++;
f(n,m);a[n][m]=0;k--;
}}
}
main()
{ printf(" Please wait for a few minutes. ");
f(0,0); }
int a[8][8]=;
void f(int x,int y)
{int m,n,i;
if(k==65){PRintf(" ");
for(a1=0;a1<8;a1++)
{for(a2=0;a2<8;a2++)
printf("%3d",a[a1][a2]);
printf(" "); } }
else
for(i=1;i<64;i++)
{m=i/8;n=i%8;
if(((n-x)*(n-x)+(m-y)*(m-y))==5&&a[n][m]==0)
{ a[n][m]=k++;
f(n,m);a[n][m]=0;k--;
}}
}
main()
{ printf(" Please wait for a few minutes. ");
f(0,0); }
更多精彩
赞助商链接