Codeforces 987B. High School: Become Human

解题思路:

  1.题意:判断x^y和y^x谁大谁小。

  2.由于x^y和y^x太大了,时间复杂度也不允许,所以做同等变换,比较e^(ylnx)和e^(xlny)。

  3.即为比较ylnx和xlny的大小。

注意:

  由于涉及到浮点数,我们需要处理一下误差,若差值在1e-6范围内视为相等。

 

代码:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
    ios::sync_with_stdio(false); 
    double x,y;
    cin >> x >> y;
    double a = 1.0*x*log(y);
    double b = 1.0*y*log(x);
//    cout << fabs(a-b) << endl;
    if(fabs(a-b) < 1e-6){
        cout << "=" << endl;
    }else if(b > a){
        cout << ">" << endl; 
    }else if(b < a){
        cout << "<" << endl;
    }
    return 0;
}

 

posted @ 2018-05-30 11:08  ninding  阅读(263)  评论(0编辑  收藏  举报