lee最短路算法_Lee算法的解釋:迷宮運行并找到最短路徑

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最短路算法

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/390888.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/390888.shtml
英文地址,請注明出處:http://en.pswp.cn/news/390888.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

gan訓練失敗_我嘗試過(但失敗了)使用GAN來創作藝術品,但這仍然值得。

gan訓練失敗This work borrows heavily from the Pytorch DCGAN Tutorial and the NVIDA paper on progressive GANs.這項工作大量借鑒了Pytorch DCGAN教程 和 有關漸進式GAN 的 NVIDA論文 。 One area of computer vision I’ve been wanting to explore are GANs. So when m…

怎么樣實現對一個對象的深拷貝

問題&#xff1a;怎么樣實現對一個對象的深拷貝 使用深拷貝的方法有點難實現啊。要保證原來的對象和克隆對象不是共享同一個引用的步驟是什么啊&#xff1f; 回答一 一種安全的方法是先序列化對象&#xff0c;然后反序列化。這保證了所有東西都是一個新的引用。 這里有一篇…

19.7 主動模式和被動模式 19.8 添加監控主機 19.9 添加自定義模板 19.10 處理圖形中的亂碼 19.11 自動發現...

2019獨角獸企業重金招聘Python工程師標準>>> 19.7 主動模式和被動模式 ? 主動或者被動是相對客戶端來講的 ? 被動模式&#xff0c;服務端會主動連接客戶端獲取監控項目數據&#xff0c;客戶端被動地接受連接&#xff0c;并把監控信息傳遞給服務端 服務端請求以后&…

Codeforces Round #444 (Div. 2) C.Solution for Cube 模擬

向題解低頭&#xff0c;向大佬低頭(。﹏。)orz……模擬也不能亂模啊……要好好分析題意&#xff0c;簡化簡化再簡化orz敲黑板 六個面的魔方&#xff0c;能一步還原的情況一定是只有2個面是單色&#xff0c;其余四個面&#xff0c;每個面2種顏色&#xff0c;而且不會出現任意兩面…

fcc認證_介紹fCC 100:我們對2019年杰出貢獻者的年度總結

fcc認證2019 has been a big year for the global freeCodeCamp community.對于全球freeCodeCamp社區來說&#xff0c;2019年是重要的一年。 More people are answering questions on the forum. 越來越多的人在論壇上回答問題。 Our publication has several new, rising aut…

華盛頓特區與其他地區的差別_使用華盛頓特區地鐵數據確定可獲利的廣告位置...

華盛頓特區與其他地區的差別深度分析 (In-Depth Analysis) Living in Washington DC for the past 1 year, I have come to realize how WMATA metro is the lifeline of this vibrant city. The metro network is enormous and well-connected throughout the DMV area. When …

Windows平臺下kafka環境的搭建

近期在搞kafka&#xff0c;在Windows環境搭建的過程中遇到一些問題&#xff0c;把具體的流程幾下來防止后面忘了。 準備工作&#xff1a; 1.安裝jdk環境 http://www.oracle.com/technetwork/java/javase/downloads/index.html 2.下載kafka的程序安裝包&#xff1a; http://kafk…

deeplearning.ai 改善深層神經網絡 week2 優化算法

這一周的主題是優化算法。 1. Mini-batch&#xff1a; 上一門課討論的向量化的目的是去掉for循環加速優化計算&#xff0c;X [x(1) x(2) x(3) ... x(m)]&#xff0c;X的每一個列向量x(i)是一個樣本&#xff0c;m是樣本個數。但當樣本很多時&#xff08;比如m500萬&#xff09…

gcc匯編匯編語言_什么是匯編語言?

gcc匯編匯編語言Assembly Language is the interface between higher level languages (C, Java, etc) and machine code (binary). For a compiled language, the compiler transforms higher level code into assembly language code.匯編語言是高級語言(C &#xff0c;Java等…

鋪裝s路畫法_數據管道的鋪裝之路

鋪裝s路畫法Data is a key bet for Intuit as we invest heavily in new customer experiences: a platform to connect experts anywhere in the world with customers and small business owners, a platform that connects to thousands of institutions and aggregates fin…

leetcode421. 數組中兩個數的最大異或值(貪心算法)

給你一個整數數組 nums &#xff0c;返回 nums[i] XOR nums[j] 的最大運算結果&#xff0c;其中 0 ≤ i ≤ j < n 。 進階&#xff1a;你可以在 O(n) 的時間解決這個問題嗎&#xff1f; 示例 1&#xff1a; 輸入&#xff1a;nums [3,10,5,25,2,8] 輸出&#xff1a;28 解…

IBM推全球首個5納米芯片:計劃2020年量產

IBM日前宣布&#xff0c;該公司已取得技術突破&#xff0c;利用5納米技術制造出密度更大的芯片。這種芯片可以將300億個5納米開關電路集成在指甲蓋大小的芯片上。 IBM推全球首個5納米芯片 IBM表示&#xff0c;此次使用了一種新型晶體管&#xff0c;即堆疊硅納米板&#xff0c;將…

drop sql語句_用于從表中刪除數據SQL Drop View語句

drop sql語句介紹 (Introduction) This guide covers the SQL statement for dropping (deleting) one or more view objects.本指南介紹了用于刪除(刪除)一個或多個視圖對象SQL語句。 A View is an object that presents data from one or more tables.視圖是顯示來自一個或多…

async 和 await的前世今生 (轉載)

async 和 await 出現在C# 5.0之后&#xff0c;給并行編程帶來了不少的方便&#xff0c;特別是當在MVC中的Action也變成async之后&#xff0c;有點開始什么都是async的味道了。但是這也給我們編程埋下了一些隱患&#xff0c;有時候可能會產生一些我們自己都不知道怎么產生的Bug&…

項目案例:qq數據庫管理_2小時元項目:項目管理您的數據科學學習

項目案例:qq數據庫管理Many of us are struggling to prioritize our learning as a working professional or aspiring data scientist. We’re told that we need to learn so many things that at times it can be overwhelming. Recently, I’ve felt like there could be …

react 示例_2020年的React Cheatsheet(+真實示例)

react 示例Ive put together for you an entire visual cheatsheet of all of the concepts and skills you need to master React in 2020.我為您匯總了2020年掌握React所需的所有概念和技能的完整視覺摘要。 But dont let the label cheatsheet fool you. This is more than…

leetcode 993. 二叉樹的堂兄弟節點

在二叉樹中&#xff0c;根節點位于深度 0 處&#xff0c;每個深度為 k 的節點的子節點位于深度 k1 處。 如果二叉樹的兩個節點深度相同&#xff0c;但 父節點不同 &#xff0c;則它們是一對堂兄弟節點。 我們給出了具有唯一值的二叉樹的根節點 root &#xff0c;以及樹中兩個…

Java之Set集合的怪

工作中可能用Set比較少&#xff0c;但是如果用的時候&#xff0c;出的一些問題很讓人摸不著頭腦&#xff0c;然后我就看了一下Set的底層實現&#xff0c;大吃一驚。 ###看一個問題 Map map new HashMap();map.put(1,"a");map.put(12,"ab");map.put(123,&q…

為mysql數據庫建立索引

前些時候&#xff0c;一位頗高級的程序員居然問我什么叫做索引&#xff0c;令我感到十分的驚奇&#xff0c;我想這絕不會是滄海一粟&#xff0c;因為有成千上萬的開發者&#xff08;可能大部分是使用MySQL的&#xff09;都沒有受過有關數據庫的正規培訓&#xff0c;盡管他們都為…

查詢數據庫中有多少個數據表_您的數據中有多少汁?

查詢數據庫中有多少個數據表97%. That’s the percentage of data that sits unused by organizations according to Gartner, making up so-called “dark data”.97 &#xff05;。 根據Gartner的說法&#xff0c;這就是組織未使用的數據百分比&#xff0c;即所謂的“ 暗數據…