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;
}