hdu 2899 Strange fuction

很好的数学题,求导判断+二分找最小点

http://acm.hdu.edu.cn/showproblem.php?pid=2899

#include<iostream>
#include<vector>
#include<map>
#include<stack>
#include<algorithm>
#include<queue>
#include<list>
#include<set>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stdio.h>
#include<ctype.h>
#include<iomanip>
using namespace std;

#define LL long long

double y=0;
double chk(double x)
{
    return 42.0*pow(x,6.0)+48.0*pow(x,5.0)+21.0*pow(x,2.0)+10.0*x-y;
}
double cal(double x)
{
    return 6.0*pow(x,7.0)+8.0*pow(x,6.0)+7.0*pow(x,3.0)+5.0*pow(x,2.0)-x*y;
}

int main()
{
    int t;
    while(scanf("%d",&t)!=EOF)
    {
    int i,j,k;
    while(t--)
    {
    scanf("%lf",&y);
    double l=0.0,r=100.0,mid;
    while(r-l>1e-6)
    {
        mid=(l+r)/2.0;
        if(chk(mid)<=0.0)
        {

        l=mid;
        }
        else
        r=mid;
    }
    printf("%.4f\n",cal(mid));
    }
    }
    return 0;
}


 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值