c 数据算法参考书本 跳斑马
来源:互联网 发布:数据培训 编辑:程序博客网 时间:2024/05/19 18:10
#include <stdio.h>#include <stdlib.h>#define X 8#define Y 8int chess[X][Y];int nextxy(int *x, int *y, int conut){switch (conut){case 0:if (*x + 2 <= X - 1 && *y - 1 >= 0 && chess[*x + 2][*y - 1] == 0){*x = *x + 2;*y = *y - 1;return 1;}break;case 1:if (*x + 2 <= X - 1 && *y +1 <=Y-1 &&chess[*x + 2][*y+1] == 0){*x = *x +2;*y = *y +1;return 1;}break;case 2:if (*x + 1 <= X - 1 && *y - 2 >=0 && chess[*x + 1][*y -2] == 0){*x = *x + 1;*y = *y - 2;return 1;}break;case 3:if (*x + 1 <=X-1 && *y +2 <=Y-1 && chess[*x +1][*y +2] == 0){*x = *x +1;*y = *y +2;return 1;}break;case 4:if (*x - 2 >= 0 && *y - 1>=0 && chess[*x - 2][*y -1] == 0){*x = *x - 2;*y = *y - 1;return 1;}break;case 5:if (*x - 2 >= 0 && *y +1 <=Y-1 && chess[*x - 2][*y +1] == 0){*x = *x - 2;*y = *y+1;return 1;}break;case 6:if (*x - 1 >= 0 && *y - 2 >=0&& chess[*x - 1][*y - 2] == 0){*x = *x - 1;*y = *y -2;return 1;}break;case 7:if (*x - 1 >= 0 && *y+2 <= Y - 1 && chess[*x - 1][*y + 2] == 0){*x = *x - 1;*y = *y + 2;return 1;}break;}return 0;}int TravelChessBoard(int x, int y, int tag){int x1 = x, y1 = y, flag = 0, conut = 0;chess[x][y] = tag;if (tag == X*Y)return 1;flag = nextxy(&x1, &y1, conut);while (flag == 0 && conut < 7){conut = conut += 1;flag = nextxy(&x1, &y1, conut);}while (flag){if (TravelChessBoard(x1, y1, tag + 1)){return 1;}x1 = x;y1 = y;conut = conut + 1;flag = nextxy(&x1, &y1, conut);while (flag == 0 && conut < 7){conut = conut + 1;flag = nextxy(&x1, &y1, conut);}}if (!flag)chess[x][y] = 0;return 0;}void main111(){int i, j;for (i = 0; i < X;i++)for (j = 0; j < Y; j++)chess[i][j] = 0;if (TravelChessBoard(2, 0, 1)){for (i = 0; i < X; i++){for (j = 0; j < Y; j++)printf("%4d", chess[i][j]);printf("\n");}printf("The horse has travelled the chess borad\n");}elseprintf("The horse cannot travel the chess boarf\n");getchar();system("pause");}
0 0
- c 数据算法参考书本 跳斑马
- 参考书本 背包问题
- 书本的算法2
- 斑马
- 斑马斑马
- c#迭代器照抄书本《深入学习c#》
- 《斑马斑马》吉他谱
- 算法参考
- 算法参考
- Linux C 函数参考(数据结构及算法)
- Linux C 函数参考之数据结构及算法篇
- Linux C Function()参考之数据结构及算法篇
- 【动态规划】书本整理 book.pas/c/cpp
- 斑马问题
- C 数据算法 八皇后
- 学习书本
- 书本整理
- 书本整理
- 备注 break continue return
- springmvc4 mybatis 整合 框架源码 bootstrap html5 mysql oracle
- log的简单说明
- Java源码 SpringMVC Mybatis Shiro Bootstrap Rest Webservice
- iOS 根据经纬度获取地名,根据地名获取经纬度
- c 数据算法参考书本 跳斑马
- win7 破解激活工具--windows loader
- html网页切换和framset布局
- 参考书本 背包问题
- 算法:堆排序之每次输入插一次堆&输入完成后建堆
- 管道是否需要使用xargs及其用法
- 常用获取inflate的方式
- 算法 排序 快排
- JavaWeb学习(三):jsp