### HDU 2899 Strange fuction(二分或三分)

```#include <cstdio>
#include <cmath>
using namespace std;
#define eps 1e-6
double F(double x,double y){//求值
return 6*pow(x,7)+8*pow(x,6)+7*pow(x,3)+5*pow(x,2)-y*x;
}

double f(double x){//對x求導
return 42*pow(x,6)+48*pow(x,5)+21*pow(x,2)+10*x;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
double y;
scanf("%lf",&y);
double left=0,right=100,mid;
while(right-left>eps)
{
mid=(left+right)/2;
if(f(mid)<y) left=mid;
else right=mid;
}
printf("%.4lf\n",F(mid,y));
}
return 0;
}```

```#include <cstdio>
#include <cmath>
using namespace std;
#define eps 1e-6
double F(double x,double y){//求值
return 6*pow(x,7)+8*pow(x,6)+7*pow(x,3)+5*pow(x,2)-y*x;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
double y;
scanf("%lf",&y);
double left=0,right=100,mid,midmid;
while(right-left>eps)
{
mid=(left+right)/2;
midmid=(mid+right)/2;
if(F(mid,y)<F(midmid,y)) right=midmid;
else left=mid;
}
printf("%.4lf\n",F(mid,y));
}
return 0;
}```

#### 注意！

© 2014-2022 ITdaan.com 联系我们：