题意:模拟国际象棋马的走棋方式,和中国象棋一样马走日,8X8的棋盘,问从起点到终点的最短步数,国际象棋中数字代表行row,字母代表列column,

思路:记忆化深搜、

 #include<cstdio>
#include<cstring>
const int qq=+,no=1e7;
int tx,ty,minx;
char map[qq][qq];
int dis[qq][qq];
void dfs(int x,int y,int cnt)
{
if(x<=||y<=||x>||y>) return;
if(cnt>=minx) return;
if(cnt>=dis[x][y]) return;
if(x==tx&&y==ty) if(cnt<minx) minx=cnt;
dis[x][y]=cnt;
dfs(x+,y+,cnt+);
dfs(x+,y-,cnt+);
dfs(x-,y+,cnt+);
dfs(x-,y-,cnt+);
dfs(x+,y+,cnt+);
dfs(x+,y-,cnt+);
dfs(x-,y+,cnt+);
dfs(x-,y-,cnt+);
return;
}
int main()
{
char str[];
while(scanf("%c%c%*c%c%c",&str[],&str[],&str[],&str[])!=EOF){
getchar();
int sx,sy;
sx=str[]-'';sy=str[]-'a'+; //自己开始就没有+1,然后又调试了十几分钟
tx=str[]-'';ty=str[]-'a'+;
for(int j,i=;i<=;++i)
for(j=;j<=;++j)
dis[i][j]=no;
minx=no;
dfs(sx,sy,);
printf("To get from %c%c to %c%c takes %d knight moves.\n",str[],str[],str[],str[],minx);
}
}

最新文章

  1. Java实现颜色渐变效果
  2. Java中读取xml方法
  3. iOS UIImageView设置为圆形
  4. wpf:小问题总结
  5. 【Xamarin报错】AndroidManifest.xml : warning XA0101: @(Content) build action is not supported
  6. Create Timer Example To Show Image Presentation in Oracle Forms
  7. $.toJSON的用法或把数组转换成json类型
  8. GPS(1)核心API及3种列出LocationProvider的方法
  9. HTML之学习笔记(九)表单
  10. 关于python 函数参数
  11. 2018年web前端学习路线图
  12. Windows Server 安装后无法使用无线与音频
  13. was cached in the local repository, resolution will not be reattempted until the update interval of fintech has elapsed or updates are forced
  14. webpack 4 简单介绍
  15. 背水一战 Windows 10 (120) - 后台任务: 后台上传任务
  16. nginx跨域的简单应用
  17. EDK II之USB总线驱动的实现框架
  18. kafka配置监控和消费者测试
  19. 远程访问Centos6.5上的mysql或者mariadb(navicat)
  20. Tomcat,JBoss与JBoss Web

热门文章

  1. 一位AI研究员+区块链创业者的终极展望:AI DAO将统治世界
  2. 学习笔记(3)---安装SVM问题及解决方法
  3. DirectX11笔记(四)--渲染管线
  4. Git-svn:用git管理svn仓库
  5. 介绍vue项目中的axios请求(get和post)
  6. Directx11教程(60) tessellation学习(2)
  7. FinalShell for Mac
  8. Person Re-identification 系列论文笔记(二):A Discriminatively Learned CNN Embedding for Person Re-identification
  9. Android EditText____TextchangedListener
  10. C# 从零开始写 SharpDx 应用 初始化dx修改颜色