当前位置: 首页 > news >正文

439 - Knight Moves (UVA)

题目链接如下:

Online Judge

UVA439 骑士的移动 - 锦依卫议事堂 - 洛谷博客 这里有好几个特别厉害的解法...先存着慢慢看。

我的代码如下:

#include <iostream>
#include <deque>
#include <string>
// #define debugstruct node{std::string loc;int step;
};
std::string s1, s2;
int dx[] = {2, 1, -1, -2, -2, -1, 1, 2};
int dy[] = {1, 2, 2, 1, -1, -2, -2, -1};int calStep(){if (s1 == s2){return 0;}node temp;temp.loc = s1;temp.step = 0;std::deque<node> dq;dq.push_back(temp);while (!dq.empty()){node curr = dq.front();dq.pop_front();for (int u = 0; u < 8; ++u){node tmp;tmp.loc.push_back(curr.loc[0] + dx[u]);tmp.loc.push_back(curr.loc[1] + dy[u]);if (tmp.loc == s2){return curr.step + 1;}if (tmp.loc[0] >= 'a' && tmp.loc[0] <= 'h' && tmp.loc[1] >= '1' && tmp.loc[1] <= '8'){tmp.step = curr.step + 1;dq.push_back(tmp);}}}
}int main(){#ifdef debugfreopen("0.txt", "r", stdin);freopen("1.txt", "w", stdout);#endifwhile (std::cin >> s1 >> s2){printf("To get from %s to %s takes %d knight moves.\n", s1.c_str(), s2.c_str(), calStep());}#ifdef debugfclose(stdin);fclose(stdout);#endifreturn 0;
}

http://www.lryc.cn/news/280423.html

相关文章:

  • 数据结构(c)冒泡排序
  • 并发编程之并发容器
  • K8s---存储卷(动态pv和pvc)
  • JS判断对象是否为空对象的几种方法
  • 算法通关村第十五关—用4KB内存寻找重复元素(青铜)
  • 【PHP】判断字符串是否是有效的base64编码
  • 鼎盛合|测量精度SOC芯片开发中的技术问题整理
  • sql | 学生参加各科考试次数
  • uniapp(vue2)+VoerkaI18n多语言
  • C51--测速小车
  • ORACLE报错:ORA-04091 表XXX发生了变化,触发器/函数不能读它
  • Arm LDM和STM的寻址方式
  • 网络技术基础入门全套实验-厦门微思网络CCNA实验手册
  • 【已解决】C语言实现多线程检索数据
  • 用LM Studio:2分钟在本地免费部署大语言模型,替代ChatGPT
  • C语言经典算法之直接排序算法
  • 前端开发vscode 常用插件记录
  • 基于JavaWeb+BS架构+SpringBoot+Vue基于web的多媒体素材管理系统的设计和实现
  • 常用的dom操作
  • Hotspot源码解析-第十七章-虚拟机万物创建(三)
  • Spring MVC 的RequestMapping注解
  • navicat for oracle
  • 行业分享----dbaplus174期:美团基于Orchestrator的MySQL高可用实践
  • springboot集成钉钉通知
  • 直播预告丨看零售场,如何玩转 MaaS
  • 高创新!EI论文复现+改进:聚合温度调控策略的综合能源系统/微电网/虚拟电厂多目标优化调度程序代码!
  • 详解Matlab深度学习进行波形分割
  • 如何在Windows 10/11的防火墙中禁止和允许某个应用程序,这里提供详细步骤
  • vivado 添加现有IP文件、生成IP
  • C++右值引用,右值引用与const引用的区别