#include<stdio.h>
#include<time.h>
#define N 8
#define M 64
int t ;
int r[N+4][N+4];
void travel(int x,int y,int n)
{
if (r[x][y])return;
r[x][y]=n;
if(n==M){t=1;return;}
travel(x+1,y+2,n+1);
if (t==1)return;
travel(x+1,y-2,n+1);
if (t==1)return;
travel(x-1,y+2,n+1);
if (t==1)return;
travel(x-1,y-2,n+1);
if (t==1)return;
travel(x+2,y+1,n+1);
if (t==1)return;
travel(x+2,y-1,n+1);
if (t==1)return;
travel(x-2,y+1,n+1);
if (t==1)return;
travel(x-2,y-1,n+1);
if (t==1)return;
r[x][y]=0;
return;
}
int main()
{
int i,j;
clock_t in,out;
for (i=0;i<2;i++)
{
for (j=0;j<N+4;j++)
{
r[i][j]=1;
r[j][i]=1;
}
}
for (i=N+2;i<N+4;i++)
{
for (j=0;j<N+4;j++)
{
r[i][j]=1;
r[j][i]=1;
}
}
in=clock();
travel(2,2,1);
out=clock();
for (i=2;i<N+2;i++)
{
for (j=2;j<N+2;j++)
{
printf("%2d ",r[j][i]);
}
putchar('\n');
}
printf("%lf",(double)(out-in)/CLOCKS_PER_SEC);
}
前阵子写的 |