NCD Salary【签到题】

题目描述:原题链接

Each month, each student in NCD gets a salary of B1P1 Liras. But when Ghaffar went to get his salary this month, he was surprised that he was given B2P2 Liras.

Because he is lazy, he asked you to determine whether the new salary is bigger or smaller than the original salary.

Input
The first line of input will be T, number of test cases.

Each test case is described by four space separated integers, B1,P1,B2,P2 numbers given in the statement.

0≤B,P≤106
It’s guaranteed that at least one of the B1,P1 and one of the B2,P2 is not equal to zero.

Output
For each test case print “Congrats” if the new salary is bigger, print “HaHa” if it is smaller, and print “Lazy” if it is the same amount.

Example

input
3
2 3 4 2
2 2 3 1
2 4 4 2

output
Congrats
HaHa
Lazy

思路:

因为直接对底数或者指数相除容易出现除数是0的情况,所以做等式变换。B1^(P1) <= B2^(P2) 等于 P1lnB1<=P2lnB2。之后要对精度做处理,并且对指数为零的情况进行特判。要注意这里要用 double eps,用 int 就等于0。

#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;
typedef long long ll;
const int N=100010;
double eps=1e-8;

int main()
{
     
    int T;
    scanf("%d",&T);
    while(T--)
    {
     
        int a1,b1,a2,b2;
        scanf("%d %d %d %d",&a1,&b1,&a2,&b2);

        if(a1==0 || a2==0)
        {
     
            if(a1==0 && a2!=0) printf("Congrats\n");
            else if(a1!=0 && a2==0) printf("HaHa\n");
            else printf("Lazy\n");
            continue;
        }

        double key1=b1*log(a1);
        double key2=b2*log(a2);
        if(abs(key1-key2)<eps) printf("Lazy\n");
        else if(key1<key2) printf("Congrats\n");
        else printf("HaHa\n");
    }
    return 0;
}

你可能感兴趣的:(NCD Salary【签到题】)