Copier Reduction
InterviewTime limit1sMemory limit128 MB
Given an image and paper size in millimeters, find the largest integer percentage scale (with optional 90-degree rotation) that still fits on the paper.
- Level
Easy3 of 10
- Topics
- Math, Implementation, Brute force, Geometry
- Solved
- No attempts yet
Problem
You need to copy an mm image onto a mm sheet of paper, keeping the image as large as possible.
You may rotate the image by 90 degrees (landscape orientation). If it still does not fit, you may shrink it uniformly to an integer percentage of its original size.
For example, to copy a 560×400 mm image onto a 216×280 mm sheet, you can rotate it to landscape and reduce it to 50% of its original size, giving 200×280 mm, which fits without overlapping any edge.
Given the image and paper dimensions, determine the largest integer percentage of the original size at which the image still fits on the paper (after an optional 90° rotation).
Input
The input contains one or more test cases. Each test case is a single line with four positive integers , , , and separated by spaces, describing an mm image and a mm sheet of paper. Every value is less than 1000.
The input ends with a line containing four zeros, which must not be processed.
Output
For each test case, print the largest integer percentage (with ) such that the image, scaled to of its original size and optionally rotated 90°, fits on the paper without overlapping any edge. If the image already fits at its original size, print 100%.
It is guaranteed that the answer is always an integer percentage between 1% and 100% inclusive. Print each answer on its own line, followed by a percent sign, exactly as shown in the examples.