1002 Strange fuction

1002  Strange fuction 

一个方程F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x,求他的最小值.

 
 
求导得 F'(x)= 42 *pow(x, 6 )+ 48 *pow(x, 5 )+ 21 *pow(x, 2 )+ 10 *x-y;
另其为0,则y= 42 *pow(x, 6 )+ 48 *pow(x, 5 )+ 21 *pow(x, 2 )+ 10 *x;
用二分法。

#include <stdio.h>
#include <string.h>
#include <queue>
#include <iostream>
#include <map>
#include <algorithm>
using namespace std;
double y; 
double f(double N)
{
    return 42*N*N*N*N*N*N+48*N*N*N*N*N+21*N*N+10*N;
}
double erfen(double left,double right)
{
    double mid;
    while(right-left>1e-7)
    {
        mid=(right+left)/2;
        if(f(mid)-y<1e-7)
        {
            left=mid;
        }
        else 
        {
            right=mid;
        }
    }
    return right;
}
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%lf",&y);
        double t=erfen(0.0,18.0);
        double b=6*t*t*t*t*t*t*t+8*t*t*t*t*t*t+7*t*t*t+5*t*t-y*t;
        printf("%.4lf\n",b); 
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值