活跃农民
- 积分
- 699
- 大米
- 颗
- 鳄梨
- 个
- 水井
- 尺
- 蓝莓
- 颗
- 萝卜
- 根
- 小米
- 粒
- 学分
- 个
- 注册时间
- 2016-7-19
- 最后登录
- 1970-1-1
|
交作业!!!
第二部分这样想的:
1. initialize: the same as the hw, all walls are present (true), no cells are connected, every cell is labelled unvisited (vistited = false)
1. start: randomly choose one cell as the starting point, change visted to true
2. starting dfs: for all the neighbors (3 of them),
if wall between this cell and the neigbor is true, and the neigbor is vot visitied, (the condition garantees that every pair is has only one path)
break this wall and set the neighbor to be visited.
recursively run dfs on this neigbor (dfs makes sure that every cell is considered, i.e either break the wall or path already exists)
(random starts and random selects neighbors is sufficient for the required randomness of the maze)
|
|