借鉴博客若干。HDU - 2899
#include <cstdio>
#include <cmath>
#include <algorithm>
#define eps 1e-7
using namespace std;
double cal(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;
double y;
scanf("%d",&t);
while(t--) {
scanf("%lf",&y);
double l=0, r=100, ans=1e13;
while (l+eps < r) {
double lmid = l+(r-l)/3;
double rmid = lmid+(r-lmid)/2;
double ltmp=cal(lmid,y), rtmp=cal(rmid,y);
if (ltmp-rtmp < eps) {
r = rmid;
ans = min(ltmp, ans);
}
else {
l = lmid;
ans = min(rtmp, ans);
}
}
printf("%.4lf\n", ans);
}
return 0;
}