日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發(fā)布時間:2023/11/29 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 lee最短路算法_Lee算法的解释:迷宫运行并找到最短路径 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

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算法是迷宮路由問題的一種可能解決方案。 如果存在的話,它總是提供最佳的解決方案,但是速度很慢,并且需要較大的內(nèi)存才能進行密集的布局。

了解其運作方式 (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來存儲步驟。 它通常使用以下步驟:

  • Choose a starting point and add it to the queue.

    選擇一個起點并將其添加到隊列中。
  • Add the valid neighboring cells to the queue.

    將有效的相鄰單元格添加到隊列中。
  • Remove the position you are on from the queue and continue to the next element.

    從隊列中刪除您所在的位置,然后繼續(xù)下一個元素。
  • 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>庫中已經(jīng)實現(xiàn)了<queue> ,但是如果您使用其他方法,則歡迎實現(xiàn)自己的隊列版本。

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

    創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎

    總結(jié)

    以上是生活随笔為你收集整理的lee最短路算法_Lee算法的解释:迷宫运行并找到最短路径的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。