Eyad and Math 、Gym - 101502H (比大小)

题目:https://cn.vjudge.net/contest/250938#problem/H

思路:大意就是比较a^b与c^d的大小,数学问题,转换思想,a^b与c^d比大小,也就相当于log(a^b) 与 log(c^d) 比大小

即b*log(a) 与 d*log(c)比大小

因为log涉及double类型的问题,所以输入可以直接用double类型,附AC代码

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

int main()
{
    int t;
    double a, b, c, d;
    double x, y;
    scanf("%d", &t);
    while(t--)
    {
        scanf("%lf%lf%lf%lf", &a, &b, &c, &d);
        x = b * log(a);
        y = d * log(c);
        if(x>=y)printf(">\n");
        else printf("<\n");
    }
    return 0;
}

也可以用int类型,在log处×1.0就OK了,附AC代码

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>


using namespace std;

int main()
{
    int t;
    int a, b, c, d;
    double x, y;
    scanf("%d", &t);
    while(t--)
    {
        scanf("%d%d%d%d", &a, &b, &c, &d);
        x = b * log(a* 1.0);
        y = d * log(c* 1.0);
        if(x>=y)printf(">\n");
        else printf("<\n");
    }
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值