CF 337B - Routine Problem

題目 : Routine Problem


題意:給定一個a:b的屏幕,要求縮成c:d格式的(只能縮不能放),輸出那條被縮的邊的縮放比


思路:簡單的比例安排,先把a,c或者b,d拉到統一大小,另外兩者等比例變換,以a,c爲例,若拉到之後有b>d就滿足縮放條件了


代碼:

#include "iostream"
#include "cstring"
#include "algorithm"
#include "cmath"
#include "cstdio"
#include "sstream"
#include "queue"
#include "vector"
#include "string"
#include "stack"
#include "cstdlib"
#include "deque"
#include "fstream"
#include "map"
using namespace std;
typedef long long LL;
const int INF = 0x1fffffff;
const int MAXN = 1000000+100;
#define eps 1e-14

int gcd(int x , int y)
{
    if(y == 0)
        return x;
    return gcd(y,x%y);
}

int main()
{
    int a,b,c,d;
    cin >>a >> b>>c>> d;

    int g1 = a*c/gcd(a,c);
    int g2 = b*d/gcd(b,d);

    int zi,mu;

    if(g1/a*b > g1/c*d)
    {
        zi = g1/a*b - g1/c*d;
        mu = g1/a*b;

        int t = gcd(zi,mu);
        cout << zi/t << '/' << mu/t << endl;
    }

    else if(g2/b*a > g2/d*c)
    {
        zi = g2/b*a - g2/d*c;
        mu = g2/b*a;

        int t = gcd(zi,mu);
        cout << zi/t << '/' << mu/t << endl;
    }

    else
        cout << 0 << '/' << a/gcd(a,b) << endl;

    return 0;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章