0x01 大致思路
题目中的迷宫是无回路的迷宫,所以不会有墙在中间并且和四周围墙分开,所以我们可以采用沿着围墙搜索的策略,即按照特定方向,绕着围墙走。至于金币嘛,搜索到们的时候一定会有遗漏的,毕竟门和金币的相对位置是不确定的。不过可以证明,这个算法搜索完一遍之后能完整走完一遍迷宫,并回到起点,所以这样的话,我们不妨暴力一点,直接搜索两遍就行,中间放一个变量存储门访问次数(因为门只有一个,一次搜索一定指挥经过一次,所以从起点开始的两次搜索之间一定能完整搜索完一次迷宫),当经过次数为二时和门进行交互走出迷宫即可。
不过话说回来,我辛辛苦苦想出来又能遍历完迷宫又能吃遍金币的算法,竟然没有一个成就嘛,差评。
0x02 大致题解
思路过两天写吧,开摆了
label inf_loop
mov |in|3
#if1
if_then_1
grt
# if_else
1
mov|from*0|out
2
mov|from*0|out
if_end_1
jmp
#if then
label if_then_1
mov|in|1
8
mov|from*0|2
sub
#if 5
if_then_5
neq
1
mov|from*0|out
2
mov|from*0|out
label if_then_5
#endif5
mov|in|1
3
mov|from*0|2
sub
#if2 ;is door
if_then_2
neq
mov|from*4|3
#if3 ; is the second time visit the door
if_then_3
neq
1
mov|from*0|4#save data in reg 4;is_visited
if_end_3
jmp
label if_then_3
4
mov|from*0|out
#return 0
label if_end_3
#endif3
label if_then_2
0
mov|from*0|out# left
#if 4
mov|in|3
if_then_4
neq
1
mov|from*0|out# forward
2
mov|from*0|out
label if_then_4
#endif4
#endif2
label if_end_1
#endif1
inf_loop
jmp