Anamorphic
Ограничения: время – 2s/4s, память – 64MiB Ввод: input.txt или стандартный ввод Вывод: output.txt или стандартный вывод
Послать решение Blockly Посылки Темы Где Обсудить (0)
Digital video images are composed of a rectangular grid of pixels. For example, a video
stored on a DVD might be 720 pixels wide and 480 pixels high (i.e. have resolution 720x480),
while a video stored on Blu-ray might be 1080 pixels wide and 584 pixels high (i.e. have resolution
1080x584). The aspect ratio of a digital image is the width in pixels divided by the height in
pixels. Although it's not necessarily true in practice, we will assume that individual pixels (in
source images and on display devices) are perfectly square and tightly packed, so that a source
image viewed on a target device with the same resolution as the image will have a viewed aspect
ratio that matches the pixel aspect ratio.
Of course, digital images are often displayed on devices with different resolutions than the source
image, sometimes with more or less pixels than the image, sometimes with different pixel aspect
ratios than the source image. In this problem, we seek fit the source image on a target display and
view it as large as possible, expanding or contracting (i.e. morphing) the source pixel dimensions to
fit the target display while maintaining the aspect ratio (as closely as possible using whole pixels).
Specifically, if the aspect ratio of the source image is greater than or equal to the aspect ratio of the
target display, then the pixel width of the source image is morphed to match the pixel width of the
target display, and the height of the source image is morphed proportionately (then rounded down
to the nearest whole number); otherwise, the pixel height of the source image is morphed to match
the pixel height of the target display, and the width of the source image is morphed proportionally
(then rounded down to the nearest whole number).
Input Format
Each line of input contains four positive integers `w_in`, `h_in`, `w_"dev"`, `h_"dev"` less than or equal to `10^6`,
separated by one or more blanks, describing the resolution of a source image and a target display.
Output Format
For each line of input, compute the resolution of the displayed image after it is morphed to fit
the target display as described above. Output the resulting pixel width and height as shown in the
output sample below.
Sample Input
1080 584 1440 900
640 480 640 480
320 240 720 405
720 540 720 405
Sample Output
w x h = 1440 x 778 pixels
w x h = 640 x 480 pixels
w x h = 540 x 405 pixels
w x h = 540 x 405 pixels
Source: California State Polytechnic University Programming Contest, Fall 2009