Struts and Springs
Time limit2sMemory limit1024 MB
Given inner windows with struts and springs, compute each window's new position and size for every resize of the outer window.
- Level
Medium4 of 10
- Topics
- Simulation, Implementation
- Solved
- No attempts yet
Problem
Struts and springs are devices that determine how rectangular windows on a screen are resized or repositioned when the enclosing window is resized. A window occupies a rectangular region of the screen, and it can enclose other windows to form a hierarchy of windows. When the outermost window is resized, each of the immediately enclosed windows may change position or size based on the placement of struts and springs. These changes may then affect the position and/or size of the windows they enclose.
A strut is conceptually a fixed length rod placed between the horizontal or vertical edges of a window, or between an edge of a window and the corresponding edge of the immediately enclosing window. When a strut connects the vertical or horizontal edges of a window, the height or width of that window is fixed. When a strut connects an edge of a window to the corresponding edge of the immediately enclosing window, the distance between those edges is fixed. Springs may be compressed or stretched, and may be used in place of struts.
Each window except the outermost has six struts or springs associated with it. One connects the vertical edges of the window, and another connects the horizontal edges. Each of the other four connects an edge of the window with the corresponding edge of the enclosing window. The sum of the lengths of the three vertical struts or springs equals the height of the enclosing window, and the sum of the three horizontal ones equals its width. When the enclosing window's width changes, any horizontal springs connected to the window are stretched or compressed in equal proportion so that their new total length equals the new width. A similar action takes place when the height changes. If all three vertical or horizontal components are struts, the top or rightmost strut, respectively, is effectively replaced by a spring.
You must write a program that takes the initial sizes and positions of a set of windows (with one window guaranteed to enclose all others), the placement of struts and springs, and requests to resize the outermost window. For each request, the program determines the modified size and position of each window.
Input
Input consists of multiple test cases, each corresponding to a different set of windows. Each test case begins with a line containing four integers nwin, nresize, owidth, and oheight. nwin is the number of windows (excluding the outer window that encloses all others), nresize is the number of resize requests for the outermost window, and owidth and oheight are the initial width and height of the outermost window.
Each of the next nwin lines contains 10 non-negative integers describing one window. The first two integers give the initial x and y displacement of the upper left corner of the window relative to the upper left corner of the outermost window. The next two give the initial width and height of the window. Each of the final six integers is either 0 (strut) or 1 (spring). The first two specify whether a strut or spring connects the vertical and horizontal edges of the window, respectively. The last four specify whether a strut or spring connects the tops, bottoms, left sides, and right sides of the window and its immediately enclosing window.
Each of the last nresize lines gives a new width and height for the outermost window, which is a resize operation. For each one, the program must determine the size and placement of each of the nwin inner windows. The test data guarantees that after every resize operation, every strut and spring has a positive integral length, and different window boundaries do not touch. Resizing never causes one window to jump inside another.
There are at most 100 windows and 100 resize operations in a test case, and the outermost window's width and height never exceed 1,000,000. The last test case is followed by a line containing four zeros.
Output
For each resize operation in a test case, print a line in the form Case k, resize operation j: where k is the test case number (starting with 1) and j is the resize operation number (1, 2, ...). Then print one line for each of the nwin inner windows, in input order, indented by four spaces, in the form Window i, x = X, y = Y, width = W, height = H, where i is the window number and X and Y are its position while W and H are its size.