這題注意精度就行,其時就是一個簡單的二分枚舉。 [cpp] #include<iostream> #include<cstdio> #include<cmath> using namespace std; const double eps=1e-4; double f(double x) { double X[4]={x}; for(int i=1;i<4;i++) X[i]=x*X[i-1]; return 8*X[3]+7*X[2]+2*X[1]+3*X[0]+6; } int main() { double x,y,result; __int64 low,mid,up; int t; scanf("%d",&t); while(t--) { scanf("%lf",&y); if(y<6) { printf("No solution!\n"); continue; } //剛開始令up=1000000,精度不夠,最後在此處糾結了半天 low=0;up=100000000000000; while(low<=up) { mid=(low+up)/2; x=mid/1000000000000.0; result=f(x); if(fabs(result-y)<eps) break; if(result<y) low=mid+1; else up=mid-1; } if(low<=up) printf("%.4lf\n",x); else printf("No solution!\n"); } return 0; }