Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
所以我们有一个 List 0.. N,以及W每个父母可以持有的项目数量(所有项目都相同):
0
N
W
假设我们有 0..12 个项目的列表。我们知道每个项目最多可以容纳 3 个项目,因此可以形成这样的树:
或者说4个项目:
我们希望列表中的项目编号获取其父编号(包含它的项目)。
父 id = floor((id - 1) / w)