函数 8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6 == Y 在X在[0,100]递增,直接二分求解
#include<iostream>
#include<cmath>
using namespace std;
/*
* 8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6 == Y
* 32*x^3 + 21*x^2 + 4*x
*/
double get_sum(double x){
return x*x*x*x*8+x*x*x*7+x*x*2+x*3+6;
}
double bin_search(double Y){
double low=0;
double high=100;
double mid;
while(low<high){
mid=(low+high)/2;
//cout<<mid<<endl;
double tmp=get_sum(mid);
if( fabs(tmp - Y) < 0.00001 )
return mid;
else if(tmp > Y)
high = mid;
else
low = mid;
}
return mid;
}
int main(){
int T;
cin>>T;
while(T--){
double Y;
cin>>Y;
if( Y<6 || Y>807020306 )
cout<<"No solution!"<<endl;
else {
double ans=bin_search(Y);
printf("%.4lf\n",ans);
}
}
return 0;
}