鱼C论坛

 找回密码
 立即注册
查看: 2209|回复: 3

e35 马走日棋盘问题

[复制链接]
发表于 2021-7-14 14:59:39 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
```
#include<stdio.h>
int qipan[8][8];
int x1,y1;
int x2,y2;
int check1 [2] ;
int k,n,m;
int check2 [2];
int count1 =1;
int count = 1;
int check(int,int);
int main ()
{
        int c,z=0,x,y,l;       
        check1[0] = -1;
        check1[1] = -1;
        for(c=0;c<8;c++)
        {
                for(z=0;z<8;z++)
                {
                        qipan[c][z] = 0;
                }
        }
        printf("请选择你的起始位置:");
        scanf("%d %d",&x,&y);
        l = qipan[x][y] = count1++;
        check(x,y);
        for(c=0;c<8;c++)
        {
                for(z=0;z<8;z++)
                {
                        printf("%2d  ",qipan[c][z]);
                }
                printf("\n");
        }
        return 0;
}
int check(int x,int y)
{
        int i=0,j=0;
        int p1[8][2] = {{x-2,y-1},{x-2,y+1},{x-1,y+2},{x-1,y-2},{x+1,y-2},{x+1,y+2},{x+2,y-1},{x+2,y+1}};
        int (*p2)[2] =p1;
        for(i=0;i<8;i++)
        {
                for(j=0;j<2;j++)
                {
                        if(*(*(p2+i)+j)>=0&&*(*(p2+i)+j)<8)
                    {
                            k = check1[j] = *(*(p2+i)+j);
                 }
                }
                if(check1[0] == -1 ||check1[1] == -1)
                {
                        check1[0] = check1[1] = -1;
                }
                if(check1[0]!=-1&&check1[1] !=-1)
                {
                        if(qipan[check1[0]][check1[1]]==0)
                        {
                                qipan[check1[0]][check1[1]] = count1++;
                                x2 = check1[0];
                                y2 = check1[1];
                                check1[0] = check1[1] = -1;
                                count++;
                        if(count<64)
                    {
                            x1 = x;
                            y1 = y;
                             check(x2,y2);
                    }
                    else
                    {
                            return 1;
                                }
                                           
                        }
                        check1[0] = check1[1] = -1;
                }
    }
        qipan[x][y] = 0;
        x = x1;
        y = y1;
        return 0;               
}
```
2.jpg
12.png
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-7-14 19:08:07 | 显示全部楼层
什么问题
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-7-15 04:28:43 | 显示全部楼层

#include<stdio.h>
int qipan[8][8];
int x1,y1;
int x2,y2;
int check1 [2] ;
int k,n,m;
int check2 [2];
int count1 =1;
int count = 1;
int check(int,int);
int main ()
{
        int c,z=0,x,y,l;       
        check1[0] = -1;
        check1[1] = -1;
        for(c=0;c<8;c++)
        {
                for(z=0;z<8;z++)
                {
                        qipan[c][z] = 0;
                }
        }
        printf("请选择你的起始位置:");
        scanf("%d %d",&x,&y);
        l = qipan[x][y] = count1++;
        check(x,y);
        for(c=0;c<8;c++)
        {
                for(z=0;z<8;z++)
                {
                        printf("%2d  ",qipan[c][z]);
                }
                printf("\n");
        }
        return 0;
}
int check(int x,int y)
{
        int i=0,j=0;
        int p1[8][2] = {{x-2,y-1},{x-2,y+1},{x-1,y+2},{x-1,y-2},{x+1,y-2},{x+1,y+2},{x+2,y-1},{x+2,y+1}};
        int (*p2)[2] =p1;
        for(i=0;i<8;i++)
        {
                for(j=0;j<2;j++)
                {
                        if(*(*(p2+i)+j)>=0&&*(*(p2+i)+j)<8)
                    {
                            k = check1[j] = *(*(p2+i)+j);
                 }
                }
                if(check1[0] == -1 ||check1[1] == -1)
                {
                        check1[0] = check1[1] = -1;
                }
                if(check1[0]!=-1&&check1[1] !=-1)
                {
                        if(qipan[check1[0]][check1[1]]==0)
                        {
                                qipan[check1[0]][check1[1]] = count1++;
                                x2 = check1[0];
                                y2 = check1[1];
                                check1[0] = check1[1] = -1;
                                count++;
                        if(count<64)
                    {
                            x1 = x;
                            y1 = y;
                             check(x2,y2);
                    }
                    else
                    {
                            return 1;
                                }
                                           
                        }
                        check1[0] = check1[1] = -1;
                }
    }
       
        x = x1;
        y = y1;
        return 0;               
}
我已经做出来了并附上我的正确代码有些代码变量是调试需要的没啥特别意义感谢各位
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-8-19 22:17:02 | 显示全部楼层
#include<stdio.h>
int qipan[8][8];
int x1,y1;
int x2,y2;
int check1 [2] ;
int k,n,m;
int check2 [2];
int count1 =1;
int count = 1;
int check(int,int);
int main ()
{
        int c,z=0,x,y,l;       
        check1[0] = -1;
        check1[1] = -1;
        for(c=0;c<8;c++)
        {
                for(z=0;z<8;z++)
                {
                        qipan[c][z] = 0;
                }
        }
        printf("请选择你的起始位置:");
        scanf("%d %d",&x,&y);
        l = qipan[x][y] = count1++;
        check(x,y);
        for(c=0;c<8;c++)
        {
                for(z=0;z<8;z++)
                {
                        printf("%2d  ",qipan[c][z]);
                }
                printf("\n");
        }
        return 0;
}
int check(int x,int y)
{
        int i=0,j=0;
        int p1[8][2] = {{x-2,y-1},{x-2,y+1},{x-1,y+2},{x-1,y-2},{x+1,y-2},{x+1,y+2},{x+2,y-1},{x+2,y+1}};
        int (*p2)[2] =p1;
        for(i=0;i<8;i++)
        {
                for(j=0;j<2;j++)
                {
                        if(*(*(p2+i)+j)>=0&&*(*(p2+i)+j)<8)
                    {
                            k = check1[j] = *(*(p2+i)+j);
                 }
                }
                if(check1[0] == -1 ||check1[1] == -1)
                {
                        check1[0] = check1[1] = -1;
                }
                if(check1[0]!=-1&&check1[1] !=-1)
                {
                        if(qipan[check1[0]][check1[1]]==0)
                        {
                                qipan[check1[0]][check1[1]] = count1++;
                                x2 = check1[0];
                                y2 = check1[1];
                                check1[0] = check1[1] = -1;
                                count++;
                        if(count<64)
                    {
                            x1 = x;
                            y1 = y;
                             check(x2,y2);
                    }
                    else
                    {
                            return 1;
                                }
                                           
                        }
                        check1[0] = check1[1] = -1;
                }
    }
       
        x = x1;
        y = y1;
        return 0;               
}
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-9-22 01:04

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表