HDU-2899 strange fuction

来源:互联网 发布:互助系统平台源码 编辑:程序博客网 时间:2024/06/14 08:05

Strange fuction

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

 

 

 

#include<stdio.h>

#include<math.h>

double hanshu(double x,double y)

{

    return 6*pow(x,7)+8*pow(x,6)+7*pow(x,3)+5*pow(x,2)-y*x;

}

double daoshu(double x,double y)

{

    return 42*pow(x,6)+48*pow(x,5)+21*pow(x,2)+10*x-y;

}

int main()

{

int T;

scanf("%d",&T);

while(T--)

{

double y,a,b,n,flag=0;

scanf("%lf",&y);

a=0.0;

b=100.0;

while(b-a>1e-6&&flag==0)

        {

            n=(a+b)/2;

            if(daoshu(n,y)>0)

                b=n;

            else if(daoshu(n,y)==0)

            {

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

                 flag=1;

            }

            else

                a=n;

        }

        if(flag==0)

        {

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

        }

}

return 0;

}

 

 题意:对于给定函数F(x) = 6 *x^7+8*x^6+7*x^3+5*x^2-y*x,在y已知的情况下,求解满足函数式的x的最小值。

分析:这个题是要求方程的最小值,首先我们来看一下他的导函数: F(x) = 42 * x^6+48*x^5+21*x^2+10*x-y(0 <= x <=100)

很显然,导函数是递增的,那么只要求出其导函数的零点就行了,用二分法求零点!


思路:因为x的范围已知,要求函数式最小值,则要判断它的增长趋势,因此需要将F(x)进行求导,可以得到F(x)在自变量范围中的增长趋势,可得当F(x)导函数为0时,F(x)函数值最小。函数式求导后,该题就变成了方程组的求解问题。

原创粉丝点击