ACM ICPC World Finals 2009

Problem I: Struts and Springs

The first part of this problem is to determine the tree hierarchy of the windows. This is fairly easy: the parent of a window W1 is the smallest window W2 such that W1 is contained in W2 (if such a window exists).

The second, more tedious part, is to handle resize operations. The horizontal and vertical dimensions can be handled separately and in the same way. Suppose some window W has its outer window’s width changed by ∆s. Let L be the total current length of the horizontal springs that control W (there are between one and three such springs). Then, a spring of length l gets resized to length l 0 = l · (1 + ∆s/L). If the device controlling the width of W is a spring, the windows inside W must now be updated since W changed width. If the device controlling the width is a strut, the windows inside W are unchanged, except that their absolute position with respect to the screen may have changed because W or one of its parents may moved.