Strange fuction—裸地三分

来源:互联网 发布:阿里云视频压缩 编辑:程序博客网 时间:2024/04/28 06:03

Description

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

2100200

Sample Output

-74.4291-178.8534

这就是一道很裸的三分题,分析可以知道它是一个二次函数

所以下意识的就用三分了

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<math.h>
using namespace std;
#define eps 1e-7


double poww(double x,double y)
{
    double mm;
    mm=6*pow(x,7)+8*pow(x,6)+7*pow(x,3)+5*pow(x,2)-y*x;
    return mm;
}






int main()
{
    int i,j;
    int   t;
    double  y,x;
    double  le,ri,mid,mmid;
    double a,b;
    while(scanf("%d",&t)!=EOF)
    {
        while(t--)
        {
           scanf("%lf",&y);
           le=0;
           ri=100;
           while(fabs(le-ri)>=eps)
           {
                mid=(le+ri)/2;
                mmid=(ri+mid)/2;
                a=poww(mid,y);
                b=poww(mmid,y);
                if(a>b)
                    le=mid;
                else ri=mmid;
           }
          printf("%.4lf\n",a);
        }
    }


}


0 0
原创粉丝点击