This page is still under construction.

Parts of this page are still being built. What you see may change.

Doing Windows

Interview

Time limit1sMemory limit128 MB

Summary
Given a screen and four windows with fixed aspect ratios, decide whether the windows can be resized and placed to tile the screen with no gaps or overlaps.
Level

Hard8 of 10

Topics
Geometry, Math, Brute force, Implementation
Solved
No attempts yet

Problem

Computer monitor screens are rectangular, and the aspect ratio of a screen is its width divided by its height. The same definition applies to a rectangular window drawn on the screen: a window's aspect ratio is its width divided by its height. For this problem, every screen and window dimension is an integer number of pixels (the individual dots, arranged in a rectangular grid, that make up an image).

Your windowing software only lets you resize a window in a way that keeps its aspect ratio unchanged. For example, a window that is 150 pixels wide and 100 pixels tall (aspect ratio 150/100=1.5150/100 = 1.5) can be resized to 225 by 150 pixels (225/150=1.5225/150 = 1.5, so the ratio is unchanged), but it cannot be resized to 224 by 150 pixels, because that would change the aspect ratio. A window can be moved to any position on the screen, but the whole window must remain visible.

Given the size of a screen and the initial sizes of four different windows (integer widths and heights), decide whether the four windows can be resized (keeping their aspect ratios) and relocated so that together they cover the entire screen exactly, with no gaps and no overlaps.

For example, consider a square screen and four square windows. Each square has aspect ratio 11, and all four can be resized to fill the screen exactly with no overlap (four equal squares arranged in a 2×22\times2 grid). This corresponds to the first example.

Input

The input consists of one or more data sets, followed by a single pair of zeros that ends the input.

Each data set is five pairs of integers. The first pair Ws HsW_s\ H_s gives the width and height of the screen. Each of the next four pairs Wi HiW_i\ H_i (for i=1,2,3,4i = 1, 2, 3, 4) gives the initial width and height of one window. All values are positive integers, and the terminating pair 0 00\ 0 is not a data set.

Output

For each data set, print one line of the form Set N: Yes or Set N: No, where NN is the data set number counting from 11. Print Yes if the four windows can be resized and relocated to cover the screen exactly with no overlap, and No otherwise.

Examples1

  1. Example 1

    Input
    400 400   10 10  35 35   15 15   100 100
    200 300   10 10  20 20   30 45   40 60
    200 250   10 10  20 20   30 45   40 60
    
    0 0
    
    Expected output
    Set 1: Yes
    Set 2: No
    Set 3: Yes