Sol:求函數的最小值。求兩次導數,判斷函數的單調性和凹凸性即可,用二分查找即可。
#include <cstdio>
#include <cmath>
using namespace std;
const double eps = 1e-10;
int T;
double y;
double G(double x)
{
return 42*pow(x,6)+48*pow(x,5)+21*pow(x,2)+10*x-y;
}
double F(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("%lf",&y);
if(G(100.0)<=0)
{
printf("%.4lf\n",F(100.0));
}
else
{
double L=0,R=100,mid;
while(R-L>=eps)
{
mid=(L+R)/2.0;
if(G(mid)<0)
L=mid;
else
R=mid;
}
printf("%.4lf\n",F(mid));
}
}
return 0;
}