CF 337B - Routine Problem

来源:互联网 发布:网络空间安全 哈工大 编辑:程序博客网 时间:2024/05/04 06:32

题目 : 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-14int 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;}