HDU 1372
2024-08-26 01:04:28
题意:模拟国际象棋马的走棋方式,和中国象棋一样马走日,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);
}
}
最新文章
- Java实现颜色渐变效果
- Java中读取xml方法
- iOS UIImageView设置为圆形
- wpf:小问题总结
- 【Xamarin报错】AndroidManifest.xml : warning XA0101: @(Content) build action is not supported
- Create Timer Example To Show Image Presentation in Oracle Forms
- $.toJSON的用法或把数组转换成json类型
- GPS(1)核心API及3种列出LocationProvider的方法
- HTML之学习笔记(九)表单
- 关于python 函数参数
- 2018年web前端学习路线图
- Windows Server 安装后无法使用无线与音频
- was cached in the local repository, resolution will not be reattempted until the update interval of fintech has elapsed or updates are forced
- webpack 4 简单介绍
- 背水一战 Windows 10 (120) - 后台任务: 后台上传任务
- nginx跨域的简单应用
- EDK II之USB总线驱动的实现框架
- kafka配置监控和消费者测试
- 远程访问Centos6.5上的mysql或者mariadb(navicat)
- Tomcat,JBoss与JBoss Web
热门文章
- 一位AI研究员+区块链创业者的终极展望:AI DAO将统治世界
- 学习笔记(3)---安装SVM问题及解决方法
- DirectX11笔记(四)--渲染管线
- Git-svn:用git管理svn仓库
- 介绍vue项目中的axios请求(get和post)
- Directx11教程(60) tessellation学习(2)
- FinalShell for Mac
- Person Re-identification 系列论文笔记(二):A Discriminatively Learned CNN Embedding for Person Re-identification
- Android EditText____TextchangedListener
- C# 从零开始写 SharpDx 应用 初始化dx修改颜色