水题:CF16C-Monitor

来源:互联网 发布:淘宝牛仔裤哪家好 知乎 编辑:程序博客网 时间:2024/05/17 02:57

Monitor

题目描述

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.

输入

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

输出

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

示例输入

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

示例输出

800 600
1920 1080
0 0


解题心得:

  1. 一道cf的水题,之前还想多了,写的比较复杂,判断了长和宽,其实没有必要很简单。直接看代码都可以看得懂。但是要注意一点要将x,y的最大公约数给除去,不然得到的不是满足的最大的面积。

#include<bits/stdc++.h>using namespace std;typedef long long ll;int main(){    ll a,b,x,y;    while(scanf("%lld%lld%lld%lld",&a,&b,&x,&y) != EOF)    {        bool flag = false;        ll k = __gcd(x,y);//一个小小的坑点        x /= k, y /= k;        ll min1 = 0,min2 = 0;        if(a < x || b < y)        {            printf("0 0\n");            continue;        }        min1 = a/x;        min2 = b/y;        ll Max = min(min1,min2);        a = (Max*x),b = (Max*y);        printf("%lld %lld\n",a,b);    }}
原创粉丝点击