您的位置:首页 > 其它

2002

2016-04-05 08:30 120 查看
题目编号:2002

简单题意:

Problem Description

Now, here is a fuction:<br>  F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x (0 <= x <=100)<br>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<br>100<br>200

 

Sample Output

-74.4291<br>-178.8534

 

Author

Redow

 
给定一个函数方程,求给定范围内函数的最值。
解题思路:求最值,首先想到求导。二次求导发现原函数单调递减。当一阶导数为0时,函数可以得到最小值。所以,使用二分法+求导解方程可以得到结果;
AC代码:#include<iostream>

#include<cstdio>

#include<cmath>

using namespace std;

double f(double x,long long y)

{

    return (42*x*x*x*x*x*x+48*x*x*x*x*x+21*x*x+10*x-y);

}

int main()

{

    int t;

    cin>>t;

    while(t--)

    {

        double mid=50.0,m=0.0,n=100.0,x,s;

        long long y;

        cin>>y;

        while(fabs(f(mid,y))>1e-5)

        {

            if((f(mid,y)>0))

            {

                n=mid;

                mid=(m+n)/2;

            }

            else if(f(mid,y)<0)

            {

                m=mid;

                mid=(m+n)/2;

            }

        }

        x=mid;

        s=6*x*x*x*x*x*x*x+8*x*x*x*x*x*x+7*x*x*x+5*x*x-y*x;

        printf("%.4lf\n",s);

    }

    return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: