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

专做短篇的网站/福州seo博客

专做短篇的网站,福州seo博客,网站建设与微店,注册公司有哪些风险题目描述 光头强正在研究国际象棋中的马的问题。他知道马可以走遍棋盘上每一个点,现在问题是,给你他想不出,如果已知初始位置和目标位置,最少需要走几次才能从初始位置到达目标位置? 要不你写个程序帮帮他&#xff1…

题目描述

光头强正在研究国际象棋中的马的问题。他知道马可以走遍棋盘上每一个点,现在问题是,给你他想不出,如果已知初始位置和目标位置,最少需要走几次才能从初始位置到达目标位置?

要不你写个程序帮帮他?

image

输入格式

输入将包含多个测试用例。每个测试用例占一行,两个长度为 22 的字符串代表起点和终点。棋盘的网格横向编号a−ha−h,纵向编号1−81−8。

输出格式

对于每个测试用例,输出一行:

To get from xx to yy takes n knight moves.

样例

输入数据 1

e2 e4
a1 b2
b2 c3
a1 h8
a1 h7
h8 a1
b1 c3
f6 f6

 

输出数据 1

To get from e2 to e4 takes 2 knight moves.
To get from a1 to b2 takes 4 knight moves.
To get from b2 to c3 takes 2 knight moves.
To get from a1 to h8 takes 6 knight moves.
To get from a1 to h7 takes 5 knight moves.
To get from h8 to a1 takes 6 knight moves.
To get from b1 to c3 takes 1 knight moves.
To get from f6 to f6 takes 0 knight moves.

代码实现

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <iomanip>
#include <set>
#include <list>
#include <string.h>
using namespace std;string star1;
string end1;
int arrl[8] = { 1, -1, 2, 2, 1, -1, -2, -2 };
int arrh[8] = { -2, -2, -1, 1, 2, 2, 1, -1 };
struct str
{int x;int y;int pos;
};
int sreach()
{int arr[9][9] = { 0 };int x = star1[0] - 'a' + 1;int y = star1[1] - '0';int rx = end1[0] - 'a' + 1;int ry = end1[1] - '0';list<struct str> list;list.push_back({ x,y,0 });arr[x][y] = 1;while (!list.empty()){int xx = list.front().x;int yy = list.front().y;for (int i = 0; i < 8; i++){if (xx + arrh[i] >= 1 && xx + arrh[i] <= 8 && yy + arrl[i] >= 1 && yy + arrl[i] <= 8 && arr[xx + arrh[i]][yy + arrl[i]] == 0){if (xx + arrh[i] == rx && yy + arrl[i] == ry){return list.front().pos + 1;}arr[xx + arrh[i]][yy + arrl[i]] = 1;list.push_back({ xx + arrh[i],yy + arrl[i],list.front().pos + 1 });       }}list.pop_front();}return 0;}int main()
{while (cin >> star1){cin >> end1;if (star1 == end1){cout << "To get from " << star1 << " to " << end1 << " takes 0 knight moves." << endl;continue;}int flag = sreach();if (flag){cout << "To get from " << star1 << " to " << end1 << " takes " << flag <<" knight moves." << endl;}}return 0;
}

http://www.whsansanxincailiao.cn/news/31993464.html

相关文章:

  • 建筑钢结构网站/百度官网认证价格
  • 北京网站制作公司招聘/漳州网络推广
  • 有什么网站开发软件/地推网推平台
  • 有什么网站可以兼职做翻译/短视频推广公司
  • 销量 wordpress/宁波网络推广seo软件
  • scratch少儿编程网站/整合营销传播的六种方法
  • 网站建设环境配置/seo网课培训
  • 厦门易尔通做网站怎么样/win7一键优化工具
  • 天津网站设计开发/常用的网络推广手段有哪些
  • 哪家做的濮阳网站建设/360收录批量查询
  • 大良营销网站建设咨询/产品网络营销方案
  • 哪些网络公司可以做机票预订网站/刚刚刚刚刚刚刚刚刚刚刚刚刚刚
  • 郑州网站优化培训机构/网站搜索引擎优化诊断
  • 怎么做北京赛网站/营销网站建设选择
  • 桂林网站优化公司/软文客
  • 网站发文超链接怎么做/网站建设公司大全
  • 一个域名怎么做多个网站/百度站长平台链接
  • 网站技术招标怎么做/重庆关键词seo排名
  • 设计网站官网入口/网络服务提供者知道或者应当知道
  • 小说网站做兼职/如何进行搜索引擎的优化
  • 做盗链电影网站怎么样/黑锋网seo
  • 如保做网站赢利/可以建网站的网络公司有哪些
  • 婚庆网站开发的意义/百度网盘登录入口
  • 使用腾讯云建设网站教程/第一站长网
  • 在线客服招聘在家工作/优化排名seo
  • 网站建设swot/百度免费发布信息网站
  • 淘宝网站制作/百度搜索引擎首页
  • 手机电商网站开发/口碑营销案例2022
  • 图书馆网站建设费用/收录好的网站
  • 职业生涯规划大赛作品/福州百度快速优化