其他分享
首页 > 其他分享> > HDU2899Strange fuction(二分/三分)

HDU2899Strange fuction(二分/三分)

作者:互联网

传送门 

题目大意:求 F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x (0 <= x <=100);的最小值

题解:求个导,二分导函数零点,就是原函数最小值所在的x。

 

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#define LL long long
using namespace std;

int T;

LL y;

double cal(double x)
{
    return 42.*pow(x,6)+48.*pow(x,5)+21.*pow(x,2)+10.*x-y;    
}

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

int main()
{
    scanf("%d",&T);
    while(T--)
    {
        scanf("%lld",&y);
        double ans,l=0,r=100;
        while(r-l>1e-5)
        {
            double mid=(l+r)/2;
        //    cout<<mid<<endl;
            if(cal(mid)<=0) ans=mid,l=mid;
            else r=mid; 
        }    
        double res=mul(ans);
        printf("%.4lf\n",res);
    }    
    return 0;
}

 

标签:二分,fuction,int,pow,LL,long,HDU2899Strange,double,include
来源: https://www.cnblogs.com/zzyh/p/11990768.html