Scratch brush HDOJ (3) [HDOJ2899 - Strange fuction]

Scratch brush HDOJ (3) [HDOJ2899 - Strange function]

Face questions

Strange fuction

Time limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 7321 Accepted Submission(s): 5057

Problem Description

Now, here is a function:

F(x)=6x7+8x6+ 7 X3+5x2- andx(0x100)

Can you find the minimum value when x is between 0 and 100.

Input

The first line of the input contains an integer T(1<=T<=100) which means the number of test cases. Then T lines follow, each line has only one real numbers Y.(0 < Y <1e10)

Output

Just the minimum value (accurate up to 4 decimal places),when x is between 0 and 100.

Sample Input

2
100
200

Sample Output

-74.4291
-178.8534

Submit Portal: the Submit

translation

When it is to seek Y When you enter a value equal to F(x) [0, 100] on zero.

Thinking

In fact, this function is unimodal in [0, 100] on.

Proof:

(kxm)=kμ(x)( M - 1 )

F(x)=42x6+48x5+21x2+ 10 x - and

y=ax6In [0,100] on a single tone increases , Y=ax5In [0,100] on a single tone increases , Y=ax2In [0,100] on a single tone increases , Y= A X in [ 0 , 100 ] on a single tone increased

F( X ) on [ 0 , 100 ] on a single tone increased

Since we can prove F(x) The derivative function F(x) Monotonically increasing in the domain, then we can define the binary zero field (refer to the specific method for a high school mathematics compulsory), find the value of this point is the point we are asking for. Final output F( A n s ) Enough.

Code

#include <cmath>
#include <iostream>

// F(x) = 6x7 + 8x6 + 7x3 + 5x2 – xy 

double y;

inline double f(const double x)
{
    return 6 * std::pow(x, 7) + 8 * std::pow(x, 6) + 7 * std::pow(x, 3) + 5 * std::pow(x, 2) - y * x;
}

inline double F(const double x)
{
    return 42 * std::pow(x, 6) + 48 * std::pow(x, 5) + 21 * std::pow(x, 2) + 10 * x;
}

int main(int argc, char ** argv)
{
    std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);
    std::cout.precision(4);
    double ans;
    double l = 0.0, r = 100.0;
    int times = 1000;
    int T;
    std::cin >> T;
    while (T--)
    {
        std::cin >> y;
        l = 0.0;
        r = 100.0;
        times = 10000;
        double eps = 1e-10;
        while (times--)
        {
            double mid = (l + r) / 2.0;
            if (F(mid)>y)
                r = mid;
            else
                l = mid;
        }
        std::cout << f(l) << std::endl;
    }
    std::cin.get();
    std::cin.get();
    return 0;
}
Published 40 original articles · won praise 0 · Views 5159

Guess you like

Origin blog.csdn.net/edward00324258/article/details/72614431