码迷,mamicode.com
首页 > 其他好文 > 详细

HDU2899Strange fuction(二分/三分)

时间:2019-12-05 18:28:11      阅读:111      评论:0      收藏:0      [点我收藏+]

标签:printf   code   using   href   ios   get   can   nbsp   pre   

传送门 

题目大意:求 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;
}

 

HDU2899Strange fuction(二分/三分)

标签:printf   code   using   href   ios   get   can   nbsp   pre   

原文地址:https://www.cnblogs.com/zzyh/p/11990768.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!