我们可以发现这个函数是单增的,那么这样二分就好了。
反思:刚转C++,不会用scanf读入实数。(scanf("%lf",&y))
//By BLADEVIL#include#include using namespace std;double f(double x) { return (8*x*x*x*x+7*x*x*x+2*x*x+3*x+6);}int task,y;int main() { scanf("%d",&task); double left=f(0),right=f(100); while (task--) { cin>>y; //printf("%.4f ",y); if ((y right)) { printf("No solution!\n"); continue; } double l=0,r=100,ans; for (int i=1;i<=30;i++) { double mid=(l+r)/2; if (f(mid)>y) { ans=mid; r=mid-1; } else l=mid+1; } printf("%.4f\n",ans); } return 0;}