S1E36课后作业求助
本帖最后由 Unicorn# 于 2020-7-25 13:44 编辑动动手1这样写有问题吗,为什么解不出来
#include <stdio.h>
void print(int map)
{
int i, j;
for(i = 0; i < 8; i++)
{
for(j = 0; j < 8; j++)
printf("%d\t", map);
putchar('\n');
}
return;
}
void step(int map, int x, int y, int count)
{
static int vector = {{2, -1}, {2, 1}, {1, -2}, {1, 2}, {-2, -1}, {-2, 1}, {-1, -2}, {-1, 2}};
int i, j, xt, yt;
map = count;
if(count == 64)
{
print(map);
return;
}
for(i = 0; i < 8; i++)
if((xt = x + vector) >= 0 && xt < 8 && (yt = y + vector) >= 0 && yt < 8 && map == 0)
step(map, xt, yt, count+1);
map = 0;
return;
}
int main(void)
{
int map = {0};
step(map, 2, 0, 1);
return 0; 换了个遍历逻辑(小甲鱼那个)就好了
页:
[1]