Sicily 1215 脫離地牢(BFS)

2022-04-14 17:10:57 字數 1868 閱讀 6967

這道題按照題意直接bfs即可,主要要注意題意中的相遇是指兩種情況:一種是同時到達同一格仔,另一種是在移動時相遇,如paris在(1,2),而helen在(1,2),若下一步paris到達(1,1),而helen達到(1,2),這種情況也算是相遇。

遇到熔漿

4546

if(visit[paris_x][paris_y][helen_x][helen_y] == 1) continue

;47 node tmp =front;

48 tmp.x1 =paris_x;

49 tmp.y1 =paris_y;

50 tmp.x2 =helen_x;

51 tmp.y2 =helen_y;

52 tmp.path[tmp.step] =i;

53 tmp.step = front.step + 1;54

q.push(tmp);

55 visit[paris_x][paris_y][helen_x][helen_y] = 1;56

if(paris_x == helen_x && paris_y == helen_y)

59if(paris_x == front.x2 && paris_y == front.y2 &&

60 helen_x == front.x1 && helen_y ==front.y1)63}

6465}66

}67}68 front.step = 256;69

return

front;70}

71int

main()

85if(_map[i][j] == 'h')

89} 90}

9192

for(int i = 0; i < 4; i++)

100 node tmp =bfs(x1, y1, x2, y2, n, m);

101if(tmp.step > 255) cout << "

impossible

"<

102else

105106

} 107

108/*

1095 5

110#####

111#p#.#

112#h!.#

113#.#.#

114#####

115wnse

116*/

sicily 1215 脫離地牢

做sicily 1215脫離地牢 這一題,一直restrict function,都快崩潰了。最後發現是記憶體洩露,就是new出來的東西沒有及時delete導致的。具體是在廣度優先搜尋的時候,每找一次鄰居就new出一些節點,有些節點已被visited了然後我直接忽略它們,實際上是得把它們delete...

sicily 1215 脫離地牢

time limit 1 secs,memory limit 32 mb 在乙個神秘的國度裡,年輕的王子paris與美麗的公主helen在一起過著幸福的生活。他們都隨身帶有一塊帶磁性的陰陽魔法石,身居地獄的魔王satan早就想得到這兩塊石頭了,只要把它們熔化,satan就能吸收其精華大增自己的魔力。...

1215 脫離地牢

此題有個巨大的吐槽的地方就是最終狀態的判定有兩種情況,相遇或者到乙個格仔裡,不要忘記當隊列為空要判定狀態為結束。還有可以用方向來代表陣列的下標,是 更具有可讀性。include include include using namespace std intconst maxn 50 char map...