Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3301 Accepted Submission(s): 2421
#include<cstdio> #include<iostream> #include<cstring> #include<cmath> #include<stdlib.h> #include<algorithm> using namespace std; double num(double x,double y) { return 6*pow(x,7.0)+8*pow(x,6.0)+7*pow(x,3.0)+5*pow(x,2.0)-y*x; } double fun(double x,double y) { return 42*pow(x,6.0)+48*pow(x,5.0)+21*pow(x,2.0)+10*x-y; } int main() { int T; double Y; scanf("%d",&T); while(T--) { scanf("%lf",&Y); if(fun(0.0,Y)>=0) printf("%.4lf\n",num(0.0,Y)); else if(fun(100.0,Y)<=0) printf("%.4lf\n",num(100.0,Y)); else { double l=0.0,mid=50.0,r=100.0; double ans1,ans2,ans3; ans1=fun(l,Y); ans2=fun(mid,Y); ans3=fun(r,Y); while(fabs(ans1-ans2)>0.000001) { if(ans2>0) { ans3=ans2; r=mid; mid=(l+r)/2; ans2=fun(mid,Y); } else { ans1=ans2; l=mid; mid=(l+r)/2; ans2=fun(mid,Y); } } printf("%.4lf\n",num(mid,Y)); } } }
原文:http://www.cnblogs.com/clliff/p/4029504.html