Ternary Search
作者:
Lemmon_kk
,
2020-07-12 15:57:57
,
所有人可见
,
阅读 521
#include <iostream>
#include <cmath>
#define eps 1e-8
using namespace std;
double y;
double fx(int x){
return 6 * pow(x, 7.0) + 8 * pow(x, 6.0) + 7 * pow(x, 3.0) + 5 * x * x - y * x;
}
double three(double l,double r){
while(l + eps < r){
double midl = (l + r) / 2.0;
double midr = (midl + r) / 2.0;
if(fx(midl) < fx(midr))
r = midr;
else
l = midl;
}
return l;
}
int main(){
int T;
cin >> T;
while(T -- ){
scanf("%lf", &y);
int t = three(0, 100);
printf("%.4f\n",fx(t));
}
return 0;
}