题目链接:http://acm.hdu.edu.cn/showproblem.pihp?pid=2899
题目大意:找出满足F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x (0 <= x <=100)的x值。注意精确度的问题。
求满足条件的x的最小值!!求导,利用单调性来找到最小值。
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
double y; double derivation(double x)
{
return *pow(x,)+*pow(x,)+*pow(x,)+*x;
} double result(double x)
{
return *pow(x,)+*pow(x,)+*pow(x,)+*pow(x,)-y*x;
} int main ()
{
int t;
cin>>t;
while (t--)
{
double x;
cin>>y;
double l=,r=;
while (r-l>1e-)
{
x=(r+l)/;
double yy=derivation(x);
if (y>yy)
l=x+1e-;
else
r=x-1e-;
}
x=(l+r)/;
printf ("%.4lf\n",result(x));
}
return ;
}