zoukankan      html  css  js  c++  java
  • CF#196DIV2:B-Routine Problem

    http://codeforces.com/contest/337/problem/B

    Manao has a monitor. The screen of the monitor has horizontal to vertical length ratioa:b. Now he is going to watch a movie. The movie's frame has horizontal to vertical length ratioc:d. Manao adjusts the view in such a way that the movie preserves the original frame ratio, but also occupies as much space on the screen as possible and fits within it completely. Thus, he may have to zoom the movie in or out, but Manao will always change the frame proportionally in both dimensions.

    Calculate the ratio of empty screen (the part of the screen not occupied by the movie) to the total screen size. Print the answer as an irreducible fractionp / q.

    Input

    A single line contains four space-separated integers a,b,c,d (1 ≤ a, b, c, d ≤ 1000).

    Output

    Print the answer to the problem as "p/q", where p is a non-negative integer,q is a positive integer and numbersp and q don't have a common divisor larger than 1.

    Sample test(s)
    Input
    1 1 3 2
    
    Output
    1/3
    
    Input
    4 3 2 2
    
    Output
    1/4
    
    Note

    Sample 1. Manao's monitor has a square screen. The movie has 3:2 horizontal to vertical length ratio. Obviously, the movie occupies most of the screen if the width of the picture coincides with the width of the screen. In this case, only 2/3 of the monitor will project the movie in the horizontal dimension:

    Sample 2. This time the monitor's width is 4/3 times larger than its height and the movie's frame is square. In this case, the picture must take up the whole monitor in the vertical dimension and only 3/4 in the horizontal dimension:


     

    题意:给出屏幕与电影长宽的比例,要求最小空白位置的长宽比

    思路:只有两种情况,长等于长,宽等于宽,然后求出空白所占的比例即可

    如果长等于长

    即有c = a

    d = a*d/c;

    所以电影面积与屏幕面积的比就是c*d/(a*b)

    代入得a*d/(b*c)

    同理,如果是的宽相等

    d = b;

    c = c*b/d;

    最后得到c*b/(a*d)

    #include <stdio.h>
    #include <algorithm>
    using namespace std;
    
    int GCD(int n,int m)
    {
        int r;
        while(m)
        {
            r = n%m;
            n = m;
            m = r;
        }
        return n;
    }
    
    int main()
    {
        int a,b,c,d,t,p,q,k;
        while(~scanf("%d%d%d%d",&a,&b,&c,&d))
        {
            p = a*d;
            q = b*c;
            if(p>q)
                swap(p,q);
            k = GCD(q,p);
            p = p/k;
            q = q/k;
            printf("%d/%d
    ",q-p,q);
        }
    
    
        return 0;
    }
    


     

  • 相关阅读:
    第06组 Alpha事后诸葛亮
    第06组 Alpha冲刺(6/6)
    第06组 Alpha冲刺(5/6)
    2020ASE-课程总结
    设计也可以按图索骥
    2020ASE第二次博客—由需求分析来看软件开发的挑战
    2020ASE第一次课程作业—期望与笃信
    git学习笔记(1)
    课程模块——课程界面与技术文档
    企业应用开发(5)--ERD初步设计
  • 原文地址:https://www.cnblogs.com/bbsno1/p/3265288.html
Copyright © 2011-2022 走看看