lee最短路算法

Lee算法是什么? (What is the Lee Algorithm?)

The Lee algorithm is one possible solution for maze routing problems. It always gives an optimal solution, if one exists, but is slow and requires large memory for dense layout.

Lee算法是迷宫路由问题的一种可能解决方案。 如果存在的话,它总是提供最佳的解决方案,但是速度很慢,并且需要较大的内存才能进行密集的布局。

了解其运作方式 (Understanding how it works)

The algorithm is a  breadth-first  based algorithm that uses  queues  to store the steps. It usually uses the following steps:

该算法是基于breadth-first算法,该算法使用queues来存储步骤。 它通常使用以下步骤:

  1. Choose a starting point and add it to the queue.选择一个起点并将其添加到队列中。
  2. Add the valid neighboring cells to the queue.将有效的相邻单元格添加到队列中。
  3. Remove the position you are on from the queue and continue to the next element.从队列中删除您所在的位置,然后继续下一个元素。
  4. Repeat steps 2 and 3 until the queue is empty.重复步骤2和3,直到队列为空。

实作 (Implementation)

C++ has the queue already implemented in the  <queue>  library, but if you are using something else you are welcome to implement your own version of queue.

C ++在<queue>库中已经实现了<queue> ,但是如果您使用其他方法,则欢迎实现自己的队列版本。

C ++代码: (C++ code:)

int dl[] = {-1, 0, 1, 0}; // these arrays will help you travel in the 4 directions more easily
int dc[] = {0, 1, 0, -1};queue<int> X, Y; // the queues used to get the positions in the matrixX.push(start_x); // initialize the queues with the start position
Y.push(start_y);void lee()
{int x, y, xx, yy;while(!X.empty()) // while there are still positions in the queue{x = X.front(); // set the current positiony = Y.front();for(int i = 0; i < 4; i++){xx = x + dl[i]; // travel in an adiacent cell from the current positionyy = y + dc[i];if('position is valid') //here you should insert whatever conditions should apply for your position (xx, yy){X.push(xx); // add the position to the queueY.push(yy);mat[xx][yy] = -1; // you usually mark that you have been to this position in the matrix}}X.pop(); // eliminate the first position, as you have no more use for itY.pop();    }
}

翻译自: https://www.freecodecamp.org/news/lee-algorithm-maze-explained/

lee最短路算法

lee最短路算法_Lee算法的解释:迷宫运行并找到最短路径相关推荐

  1. 最短路算法 :Bellman-ford算法 Dijkstra算法 floyd算法 SPFA算法 详解

     本文链接   :http://www.cnblogs.com/Yan-C/p/3916281.html . 在本文中因为邻接表在比赛中不如前向星好写,而且前向星效率并不低所以,本文的代码 存图只 ...

  2. 03 最短路 dijkstra算法spfa算法floyd算法(附带实例代码) 图论-1

    文章目录 最短路 邻接表的图如下 邻接矩阵如下图 链表实现邻接表实现代码 单源最短路径 Dijkstra 算法 朴素版本 Dijkstra 实现代码 堆优化的dijkstra算法代码实现 Bellma ...

  3. DL之BP:神经网络算法简介之BP算法简介(链式法则/计算图解释)、案例应用之详细攻略

    DL之BP:神经网络算法简介之BP算法简介(链式法则/计算图解释).案例应用之详细攻略 相关文章:DL之DNN之BP:神经网络算法简介之BP算法/GD算法之不需要额外任何文字,只需要八张图讲清楚BP类 ...

  4. 最短路最基本算法———Floyd算法

    关于floyd算法 算法简介 实现思想 核心代码 后记 一.floyd简介 引自百度百科 在计算机科学中,Floyd-Warshall算法是一种在具有正或负边缘权重(但没有负周期)的加权图中找到最短路 ...

  5. 最短路弗洛伊德(Floyd)算法加保存路径

    弗洛伊德算法大致有点像dp的推导 dp[i][j] = min(dp[i][k] + dp[k][j], dp[i][j]), 其中 i 是起始点,j 是终止点.k是它们经过的中途点. 通过这个公式不 ...

  6. ACM算法--spfa算法--最短路算法

    求单源最短路的SPFA算法的全称是:Shortest Path Faster Algorithm.      SPFA算法是西南交通大学段凡丁于1994年发表的.     从名字我们就可以看出,这种算 ...

  7. 【啊哈!算法】算法6:只有五行的Floyd最短路算法

            暑假,小哼准备去一些城市旅游.有些城市之间有公路,有些城市之间则没有,如下图.为了节省经费以及方便计划旅程,小哼希望在出发之前知道任意两个城市之前的最短路程.         上图中有 ...

  8. 有关最短路的一些算法

    http://www.cnblogs.com/hxsyl/p/3270401.html 有关最短路的一些算法

  9. 计算机短路计算基本原理,第八章第五节短路计算计算机算法.doc

    第八章第五节短路计算计算机算法 短路计算的计算机算法 前面介绍的用对称分量法计算不对称故障的计算步骤是很简明的.图8-57所示为计算简单故障(短路或断线)的计算程序原理框图. 下面对图8-57所示的框 ...

最新文章

  1. 快速读书的方法(对于理工科的可能适用)
  2. 构建之法阅读笔记之速读篇
  3. JS(本身是)单线程和UI线程同步(互斥)
  4. oracle避免同一sql多次查询,Oracle SQL - 在一个查询中生成一行答案的最简单方法,因此我不必多次运行查询?...
  5. leetcode 452. 用最少数量的箭引爆气球(贪心算法)
  6. 设计模式C++实现(2)——单例模式
  7. C#LeetCode刷题之#507-完美数(Perfect Number)
  8. python matplotlib 柱状图点击事件_Python:matplotlib分组Bar柱状图
  9. ORA-19809: limit exceeded for recovery files
  10. 网络操作系统课后练习第三章
  11. 西安计算机二级12月,2017年12月计算机二级MS Office习题答案(一)
  12. live2d_Live2D 看板娘 (WordPress)
  13. C#|图像快速傅立叶变换与反变换
  14. vSphere Esxi 7.0打包网卡驱动
  15. 【Java】有1020个西瓜,第一天卖掉总数的一半后又多卖出两个,以后每天卖剩下的一半多两个,问几天以后能卖完?
  16. 3dmax运动混合器的使用
  17. grpc-go源码剖析九之dnsResolver解释器以及实战测试coredns
  18. 蒲公英内测分发平台是干什么的呢?
  19. pytorch 中pad函数toch.nn.functional.pad()的使用
  20. echart 广州3d_一个3D可视化项目背后的心酸:ECharts-X的坎坷路

热门文章

  1. linux mysql 运行状态_Linux中使用mysqladmin extended-status配合Linux命令查看MySQL运行状态...
  2. java中的几种泛型类——HashSet、HashMap、TreeSet、TreeMap,遍历map,排序,HashTable比较
  3. 以太坊ERC20代币合约案例
  4. idea教程--Maven 骨架介绍
  5. 标准C程序设计七---77
  6. CODEVS——T1519 过路费
  7. 关于Linux的总结(三)
  8. JS模拟的Ping程序 (Web Ping)
  9. CNN tensorflow 人脸识别
  10. 关于apache和tomcat集群,线程是否占用实验