每日一題 Dungeon Master

2021-10-03 05:35:24 字數 1110 閱讀 8855

題意:

乙個3d迷宮,『s』為起點,『e』為終點,『.』為路,『#』為牆,六個方向都可以走(上下左右前後)。問幾步到終點?

題解:簡單的搜尋問題,沒有什麼建議。

個人問題:

這個題我卡了3個小時吧。原因在於暈3d,我把x,y,z的意義搞混了,我服了哦!所以如果你卡題了,就看看你的座標有問題嗎?然後看看判斷條件是不是有問題(應該是!=#,有些還會寫成==』.』)。另外,如果不是熟練掌握搜尋的話,用深蒐會時間超時,用廣搜就沒問題了

**:

///dungeon master

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

using

namespace std;

struct dataa now, well;

int a, b, c,s =

0, mink =

100;

int flag[50]

[50][

50];char brr[50]

[50][

50], cao;

int dis[6]

[3]=

,,,,

,};///可以走的幾個方向

intbfs

(dataa a)}}

return-1

;}intmain()

int s =

bfs(a);if

(s ==-1

) cout <<

<< endl;

else cout <<

"escaped in "

<< s <<

" minute(s)."

<< endl;

}return0;

}

寫在最後:

推薦兩篇部落格個人關於搜尋的總結,關於這個題一位同學的題解。這個題的方法相似度很高,而且基本就是模板題。

每日一題 1

題目詳情 peter喜歡玩數字遊戲,但數獨這樣的遊戲對他來說太簡單了,於是他準備玩乙個難的遊戲。遊戲規則是在乙個n n的 裡填數,規則 對於每個輸入的n,從左上角開始,總是以對角線為起點,先橫著填,再豎著填。這裡給了一些樣例,請在樣例中找到規律並把這個n n的 列印出來吧。輸入描述 多組測試資料 資...

每日一題2018 3 21

leetcode 2 模擬十進位制運算考察單鏈表基本操作。題無難點,個人基礎需要提高。definition for singly linked list.struct listnode class solution while p while q if shi val s next null ret...

每日一題2018 3 22

leetcode 03 最長不重複子串 第一反應就是動態規劃。看到了網上的方法一。直接把問題簡化為找兩個重複字元間的最長距離,太巧妙了!class solution if i idx max locs s i i return max ling老師的方法二 仍舊轉化為動態規劃,但是為節省空間不再開個...