1. 程式人生 > >Codeforces987B——High School: Become Human

Codeforces987B——High School: Become Human

判斷x^yy^x的大小關係
很簡單的題,取個log就行,比較坑的地方是取完log是一個浮點數,會出現精度誤差,這樣判斷大小還行,判斷相等就出問題了,雖然在本地a-b<0.0000001能過,提交上去就不行了,所以直接在輸入兩個數的時候判斷就行了

程式碼:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll x,y;
int main(void){
    scanf("%lld%lld",&x,&y);
    if(x==y){
        printf(
"=\n"); return 0; } double a=y*log(x); double b=x*log(y); if(a<b){ printf("<\n"); } else if(a>b){ printf(">\n"); } else{ printf("=\n"); } return 0; }