1 / 3
文档名称:

骑士游历源代码.doc

格式:doc   大小:15KB   页数:3页
下载后只包含 1 个 DOC 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

分享

预览

骑士游历源代码.doc

上传人:bjy0415 2018/6/26 文件大小:15 KB

下载得到文件列表

骑士游历源代码.doc

相关文档

文档介绍

文档介绍:#include""
#include ""
#define maxlen 100
int length=0; //记录所走的步数
static int bx[8] = {2,1,-1,-2,-2,-1,1,2};
static int by[8] = {1,2,2,1,-1,-2,-2,-1};
typedef struct
{
int n,m; //n 记录行数,m 记录列数
int ch;
}node;
typedef struct //定义顺序队列类型
{
node data[maxlen];
int front;
int rear;
}Sequeue;
Sequeue *setqueue()
{
Sequeue *S;
S=(Sequeue *)malloc(sizeof(Sequeue));
S->front=0;
S->rear=0;
return S;
}

void add(Sequeue *S,int x,int y,int z) //入队函数
{
if(S->rear<maxlen-1 && S->rear>=0)
{
S->rear++;
S->data[S->rear].n=x;
S->data[S->rear].m=y;
S->data[S->rear].ch=z;
}
else printf("error\n");
}
void dele(Sequeue *s) //出队函数
{
if(s->front<s->rear)
s->front++;
else
printf("error\n");
}
void judge() //判断步数
{
Sequeue *S;
S=setqueue();
int x0,y0,x1,y1,x3,y3,i,j; int count[maxlen+100];int a=0; int step[maxlen][maxlen];
char xa,xb;
for( i=0;i<maxlen;i++)
{
S->data[i].ch=0;
}

printf("请输入骑士游历的起终点:\n");
scanf(" %c,%d %c,%d",&xa,&y0,&xb,&y1);
x0=xa-'a';
x1=xb-'a';

for( i=0;i<maxlen;i++)
for( j=0;j<maxlen;j++)
{
step[i][j]=0;
}
step[x0][y0]=1;
add(S,x0,y0,0);
while(S->front<S->rear)
{
node *p;

x0=S->data[S->front+1].n;
y0=S->data[S->front+1].m;
for(int i=0;i<8;i++)
{
x3=bx[i]+x0;
y3=by[i]+y0;