Editorial for COCI '09 Contest 4 #2 Planina
Submitting an official solution before solving the problem yourself is a bannable offence.
Midpoint displacement algorithm is an actual algorithm used for landscape generation. This task shows however, a very real problem which arises in practical use. After iterations the number of vertices exceeds , even if no duplicates are stored (and doing this actually complicates the rendering process). If each vertex stores only its 3D coordinates as 3 doubles, after iterations more than 100 GB of memory is needed to store the landscape alone, with no colour, texture or shade data.
To solve this task, we reduce it to a subproblem. First note that the total number of vertices will always be the square of number of vertices in the first row (or column). If we can determine this number, obtaining the total is simple.
If we look at a single step, starting with vertices, midpoint displacement will add one vertex between each of the two neighbouring vertices. Since there are neighbours, we add new vertices so at the end of the step we now have vertices in total. This leads to a recursive formula where denotes the number of vertices after steps:
With the special case of . Using induction, we can prove that the number of vertices in the first row (or column) after steps is .
Comments