bettyyyhikl 2021-03-24 13:51 采纳率: 0%
浏览 22

骑士周游问题如何解决这一部分?

如何算出所有骑士没有走过的点并且算出距离近的目标先走?

Warnsdorff’s rule is a simple rule for a single knight’s tour that works most of the time on smaller boards. For a knight at some location (x,y) on a board:

  1. find all the unvisited locations Li that the knight can reach in one move
  2. if there is no such location Li then the tour ends (either in failure, or the knight has visited every square of the board)
  3. for each location Li found in Step 1:
    1. count the number Ni of unvisited locations that the knight can reach in one move from Li
  4. the next move in the tour is the location Li having the smallest non-zero count Ni
    1. if two or more locations Li have the same minimum count then choose any one of those locations as the next move
  • 写回答

1条回答 默认 最新

  • 槿泽 2023-03-07 20:28
    关注

    1.初始化一个棋盘,并标记起点为已经访问。
    2.对于当前位置,计算所有未访问过的位置可以在一个移动内到达的数量和位置。可以使用 Warnsdorff 的规则,为每个位置计算它们可以到达的未访问的位置数量。
    3.选择可以到达未访问位置数量最少的位置作为下一个要移动的位置。如果有多个位置可以到达相同的数量,则选择其中一个位置作为下一个要移动的位置。
    4.标记选择的下一个位置为已访问,并将当前位置更新为选择的下一个位置。
    重复步骤 2-4 直到所有位置都被访问。
    使用这种算法可以保证骑士遍历整个棋盘,同时最小化每个步骤的距离。

    评论 编辑记录

报告相同问题?

悬赏问题

  • ¥15 nginx中的CORS策略应该如何配置
  • ¥30 信号与系统实验:采样定理分析
  • ¥100 我想找人帮我写Python 的股票分析代码,有意请加mathtao
  • ¥20 Vite 打包的 Vue3 组件库,图标无法显示
  • ¥15 php 同步电商平台多个店铺增量订单和订单状态
  • ¥15 关于logstash转发日志时发生的部分内容丢失问题
  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题