题意 :给你两个指数类型的数\(A^m\)和\(B^n\),比较他们的大小.保证底数和指数中最多只有一个为0.
题解 :题目数据非常大,肯定不能直接比较.由换底公式和\(Log\)函数的性质我们知道:\(LogA^m=mLogA\),又因为\(Log\)函数是单增的,我们便可以用它来进行大小的比较.这里要注意当底数为0的时候,指数为0可以不用管.还有要记住!!! double类型比较大小会出现精度的问题,不能直接比,要用一个eps!!!
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define me memset
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
using namespace std;
typedef pair<int,int> PII;
typedef pair<long,long> PLL;
const double eps=1e-8;
int t;
double res1,res2;
int b1,p1,b2,p2;
int main() {
ios::sync_with_stdio(false);
cin>>t;
while(t--){
cin>>b1>>p1>>b2>>p2;
if(b1==0 || b2==0){
if(b1>b2) puts("HaHa");
else if(b1<b2) puts("Congrats");
else puts("Lazy");
continue;
}
res1=log(1.0*b1)*p1*1.0;
res2=log(1.0*b2)*p2*1.0;
if(fabs(res1-res2)<eps) puts("Lazy");
else if(res1<res2) puts("Congrats");
else puts("HaHa");
}
return 0;
}
原文:https://www.cnblogs.com/lr599909928/p/12830548.html