• CodeForce:16C-Monitor


    传送门:http://codeforces.com/problemset/problem/16/C

    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


    解题心得:

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

    #include<bits/stdc++.h>
    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
    ",l1,l2);
        }
        return 0;
    }
  • 相关阅读:
    Vue-router2.0学习笔记(转)
    vue-cli 搭建项目
    打开一个vue项目
    Webpack,Browserify和Gulp三者之间到底是怎样的关系
    读取ByteBuffer有效的数据
    node-sass 安装失败的解决措施[转]
    SpringCloud2.0
    Docker
    分布式文件系统之FastDFS
    SVN的使用
  • 原文地址:https://www.cnblogs.com/GoldenFingers/p/9107207.html
Copyright © 2020-2023  润新知