欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  科技

CodeForce:16C-Monitor“编程题”

程序员文章站 2022-09-28 19:20:34
Monitor time limit per test0.5 second memory limit per test64 megabytes Problem Description...

Monitor

time limit per test0.5 second
memory limit per test64 megabytes

Problem Description

Reca company makes monitors, the most popular of their models is AB999 with the screen size a?×?b centimeters. Because of some production peculiarities a screen parameters are integer numbers. Recently the screen sides ratio x:?y became popular with users. That’s why the company wants to reduce monitor AB999 size so that its screen sides ratio becomes x:?y, at the same time they want its total area to be maximal of all possible variants. Your task is to find the screen parameters of the reduced size model, or find out that such a reduction can’t be performed.

Input

The first line of the input contains 4 integers — a, b, x and y (1?≤?a,?b,?x,?y?≤?2·109).

Output

If the answer exists, output 2 positive integers — screen parameters of the reduced size model. Output 0 0 otherwise.

Examples input

800 600 4 3
1920 1200 16 9
1 1 1 2

Examples output

800 600
1920 1080
0 0


解题心得:

题意就是给你一个矩形长为a,宽为b,要你将这个矩形减掉一部分变成长宽比例为x:y,并且要求面积尽可能的大,要求你输出改变后的矩形的长和宽。 这个题真的很简单,不需要你去将什么长宽调换什么的,就老老实实的按照题意来就可以了。先将x:y变成最简比例,然后a向x缩,b向y缩,两方同时达到要求就停止。用数学方法实现就行了。
#include
using namespace std;
const int maxn = 1000;
int num[maxn];
long long a,b,x,y;

int main()
{
    while(cin>>a>>b>>x>>y)
    {
        int t=__gcd(x,y);
        x/=t;
        y/=t;
        t=min(a/x,b/y);//要两个边都同时到达比例才行
        long long l1,l2;
        l1 = x*t;
        l2 = y*t;
        printf("%lld %lld\n",l1,l2);
    }
    return 0;
}