CF 337B - Routine Problem

本文介绍了一种计算屏幕从原始尺寸缩放到目标尺寸时的缩放比例的方法,通过比较两个不同分辨率屏幕的比例来确定哪一条边需要进行缩放,并给出了具体的实现代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值