ACdream 1006 Mengzhu (數學推導)

題目鏈接:
ACdream 1006

題意:
這裏寫圖片描述
這裏寫圖片描述
這裏寫圖片描述

題解:純數學推導。
因爲:
log2(x+y)=A
log2(xy)=B
所以,
2A=x+y
2B=xy

相加一下,2x=2A+2B
所以,x=2A+2B2=2A1+2B1

到這裏,就分情況討論一下,如果A>B ,那麼:
log2(x)=A1+log2((2BA)+1)
否則就是:
log2(x)=B1+log2((2AB)+1)

AC代碼:

/*
* this code is made by LzyRapx
* Problem: 1006
* Verdict: Accepted
* Submission Date: 2017-06-23 15:52:35
* Time: 28MS
* Memory: 1844KB
*/
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        double A,B;
        cin>>A>>B;
        if(A>B)
        {
            printf("%.5lf\n",A - 1 + log2( pow(2.0,B - A) + 1 ));
        }
        else
        {
            printf("%.5lf\n",B - 1 + log2( pow(2.0,A - B) + 1 ));
        }
    }
    return 0;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章