马的遍历
来源:互联网 发布:java登录验证码实现 编辑:程序博客网 时间:2024/05/16 04:32
#include<bits.stdc++.h>
using namespace std;
int a[100][100],t=0;
int x[4]={2,1,-1,-2},y[4]={1,2,2,1};
int search(int);
int print(int);
int main()
{
a[1][1]=0;a[1][2]=0;
search(2);
};
int search(int i)
{
for (int j=0;j<=3;j++)
if (a[i-1][1]+x[j]>=0&&a[i-1][1]+x[j]<=4&&a[i-1][2]+y[j]>=0&&a[i-1][2]+y[j]<=8)
{
a[i][1]=a[i-1][1]+x[j];
a[i][2]=a[i-1][2]+y[j];
if (a[i][1]==4&&a[i][2]==8) print(i);
else search(i+1);
}
}
int print(int ii)
{
t++;
cout<<t<<": ";
for (int i=1;i<=ii-1;i++)
cout<<a[i][1]<<","<<a[i][2]<<"-->";
cout<<"4,8"<<endl;
}
using namespace std;
int a[100][100],t=0;
int x[4]={2,1,-1,-2},y[4]={1,2,2,1};
int search(int);
int print(int);
int main()
{
a[1][1]=0;a[1][2]=0;
search(2);
};
int search(int i)
{
for (int j=0;j<=3;j++)
if (a[i-1][1]+x[j]>=0&&a[i-1][1]+x[j]<=4&&a[i-1][2]+y[j]>=0&&a[i-1][2]+y[j]<=8)
{
a[i][1]=a[i-1][1]+x[j];
a[i][2]=a[i-1][2]+y[j];
if (a[i][1]==4&&a[i][2]==8) print(i);
else search(i+1);
}
}
int print(int ii)
{
t++;
cout<<t<<": ";
for (int i=1;i<=ii-1;i++)
cout<<a[i][1]<<","<<a[i][2]<<"-->";
cout<<"4,8"<<endl;
}
阅读全文
0 0
- 图的遍历算法-马遍历棋盘
- 图的遍历算法-马遍历棋盘
- 马的遍历问题
- 马的遍历
- 马的遍历问题
- 马的遍历
- 马的遍历
- 马的遍历
- 马的遍历问题
- 马的遍历
- poj1915 马的遍历
- 马的遍历问题
- 马的遍历问题
- 马的遍历问题
- [BFS]马的遍历
- P1443 马的遍历
- OJ:马的遍历
- 马的遍历
- 利用tomcat服务器配置https双向认证、https单向认证-ssl、tls
- java --导出Excel
- linux fork函数详解
- K-means algorithm原理及使用
- PAT 乙级 1026
- 马的遍历
- gg的前几天的晚上
- Java--导入Excel
- Redhat 6 隐藏登陆界面列表
- http请求相关知识
- python threading中处理主进程和子线程的关系
- 今天我可能会铭记一生
- http页面状态码-中文版
- 如何使用 Weave 网络?- 每天5分钟玩转 Docker 容器技术(63)