单调递增,二分搜索。。。
1 #include<stdio.h> 2 #define p2(x) ((x)*(x)) 3 #define p3(x) (p2(x)*(x)) 4 #define p4(x) (p2(x)*p2(x)) 5 6 double cal(double x) 7 {return 8*p4(x)+7*p3(x)+2*p2(x)+3*x+6;} 8 9 int main() 10 { 11 int t; 12 scanf("%d",&t); 13 while(t--) 14 { 15 double y; 16 scanf("%lf",&y); 17 if(cal(0)>y||cal(100)<y) 18 { 19 printf("No solution!\n"); 20 continue; 21 } 22 double l=0,r=100,tmp; 23 while(r-l>1e-6) 24 { 25 double mid=l/2+r/2; 26 if(cal(mid)>y) 27 r=mid; 28 else 29 l=mid; 30 } 31 printf("%.4lf\n",r/2+l/2); 32 } 33 }