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);
        }
    }
  • 相关阅读:
    bat常用指令记录
    物料主数据MM01扩充时默认值的设置 BADI_MATERIAL_REF
    CK11,CK11N 成本估算数据读取
    VUE中具名插槽和匿名插槽的使用
    VUE+element页面按钮调用dialog
    线程进程随笔
    "反直觉" 的Unity粒子系统API
    一个RingBuffer(C语言)
    一个极其简单(陋)的内存分配器
    nginx 转发接口出现 403 forbidden
  • 原文地址:https://www.cnblogs.com/GoldenFingers/p/9107291.html
Copyright © 2011-2022 走看看