Saturday, August 14, 2010

UVa 618 Doing Windows

Problem: given a screen of dimensions W x H and the dimensions of 4 windows all in pixels, determine if there is a layout to resize 4 windows to cover the whole screen without overlapping or out of screen but still keeps the width-height ratio of each window.

Solution: there are 2 cases while spliting the screen with a straight line: 1) 2 windows in both sides, and 2) 1 window in one side and all 3 in the other. In case 1, we can examine all 3 positions. In case 2, the problem is then recursive since it is always this case when the number of windows is less than 3.

Note: we need to splite the screen vertically and horizontally, but switching width and height just convert the splitting to the other.

No comments: