Z
Anyway, we need to put the knots on the ground, not to turn around with the move in some direction. There are both constants, "brothers," and " neighbors," and "couns" determines how close neighbour support should be at levels lower than one, and "brats" at first. The challenge then needs to be addressed from the bottom up: each support is first built up by each of its own supporters, and then we set up the current sub-referencing, computing for each of the next supports a minimum displacement relative to zero, where at each level this support will not interfere with the already established support. As a result, each subway will have a " band-in-take " parameter at every level where it has one leaf, and will be compared to the current top-level support.The algorithm looks like:BuiltTree buildTree(Tree tree) {
BuiltTree[] siblings;
foreach (subTree in tree.subTrees) siblings.push(buildTree(subTree));
BuiltTree result=new BuiltTree(); // пустое
foreach (sibling in siblings) {
int minRightPos=0;
for (i=0;i<sibling.depth;i++) {
if (result.depth<1+i) break; // у result на текущем уровне нет поддеревьев
if (i==0) minRightPos=max(minRightPos,BRATYA-sibling.left[i]+result.right[i+1])
else minRightPos=max(minRightPos,SOSEDI-sibling.left[i]+result.right[i+1]);
// считаем, как далеко нужно отставить sibling от собранного поддерева
}
result.AddSiblingAtOffset(sibling,minRightPos); // добавляем его справа
}
result.positionRoot(tree.node,minRightPos/2); // ставим корень в середину из голов поддеревьев
return result;
}
right Completed as follows: If the added support at i-m level does not have a completed right, the right does not change at i+1-m level if it does, the right becomes equal offset plus the right. left Filled in a similar way, but only if at this level it is not yet filled, as new supports add up to the right, the first with a given depth will be left behind. In progress positionRoot() all right and left is reduced to position, after which 0 is added to the beginning of the masses. I'll try to describe the algorithm disengagement. To describe the tree, I'll use Lasp's lists, numbers - leaflets, lists - support. Example: ((1) (2 3 4 5)) corresponds to such a tree: root
|
*-----*
| +-+^+-+
1 2 3 4 5
Reference tree: (((1) 2) (((3))) ((4 5 6) ((7 8 9) (10))))♪ I don't see any support from one sheet, for nothing. Support ((1) 2) is relevant: left=[0,-10,-10]; right=[0,10,-10] and the following type: *
+^+
* 2
|
1
The stars indicate the tops of the support, because there's no sign of the root on the list. (((3))) is trivial and massive left=[0,0,0,0]; right=[0,0,0,0]♪ Support ((7 8 9) (10)) the significance of the masses left=[0,-30,-50]; right=[0,30,30] and looks like: *
+--^--+
* *
+-+-+ |
7 8 9 10
Because support (7,89%) was right[1] as 20, and the displacement of the neighbour, 40, the second was replaced by 60 (0+40+20), and positionRoot was caused by a displacement of 30 (=60/2), the left support ended up falling into a minus about the total crown of -50. The 4-10 backup will look like: *
+---^----+
* *
+-+-+ +--^--+
4 5 6 * *
+-+-+ |
7 8 9 10
The right-holder ' s position is limited to a second layer where right (4,56), right[1]=20, and left[1] with a support -30, the total displacement being 90. At the bottom level, the left support has no elements, so we're missing it. As a result, positionRoot will be caused by regulation 55, and the general body looks like left=[0,-55,-75,5]; right=[0,55,85,85]♪ The assembly of the three supports will then be constructed as follows: the first one is demolished 0, second (((3))) 50 and a large third displacement of 50+40+(-75) = 165, and head will be reduced to 87.5. This will be the case: *
+----+---^-------+
* * *
+^+ | +---^----+
* 2 * * *
| | +-+-+ +--^--+
1 * 4 5 6 * *
| +-+-+ |
3 7 8 9 10
Because of roundings in the third row between the star and four lags in place of three (I considered one symbol = 10 points, but I thought the elements were not wide, so instead of 20 and 40 on the question, it would be necessary to place 40 and 60 boxes.I hope I explained.Update: Technically, after the distribution of the support, it is possible to look for the support that can be moved inside the display, not to interfere with the others, and if the problem is here it is, it is not, because after the placement of all the supporters, the most compact version of the whole tree is found in the width, and if any support can move, that is, they have a range of permitted positions. And the fact that the tree is finally very loud in the width is not a problem as such.