很好的数学题,求导判断+二分找最小点
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;
}