这题做法很显然,遇到指数函数,下意识地就要想到取对数,然而这题的坑点也在这——精度!所以采取的策略应该是尽可能地不产生小数,所以要使用y*log10 x 和 x*log10 y 他们两个来比较。
还有就是为了满足精度,我去查了返回值为long double 的log函数,其实没必要,因为在上面处理好的情况下,依然会卡精度的就是x 和 y相等的情况,所以先判断=,然后再取对数
ps:上面的思想是大牛的,下面的代码是本弱的
#include <bits/stdc++.h> using namespace std; int main(){ long double x, y; cin >> x >> y; long double ans1 = y * log10l(x); long double ans2 = x * log10l(y); if(ans1 > ans2) cout << '>' << endl; if(ans1 < ans2) cout << '<' << endl; if(ans1 == ans2) cout << '=' << endl; return 0; }