zoukankan      html  css  js  c++  java
  • 水题:CF16C-Monitor

    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
    ");
                continue;
            }
            min1 = a/x;
            min2 = b/y;
            ll Max = min(min1,min2);
            a = (Max*x),b = (Max*y);
            printf("%lld %lld
    ",a,b);
        }
    }
  • 相关阅读:
    weekly review 200812: Tire
    monthly report 200802: between the festival and the happiness
    weekly review 200813: Ill
    Android中的SharedPreferences
    如何使用Github上的开源项目
    Android四大组件
    开发者需知的10类工具
    activity中onResume()的用处
    Redhat 5.4 + ASM + RAW+ Oracle 10g RAC 安装文档
    Oracle 索引扫描的五种类型
  • 原文地址:https://www.cnblogs.com/GoldenFingers/p/9107291.html
Copyright © 2011-2022 走看看