ref:http://blog.csdn.net/acdreamers/article/details/9989197
ref:http://blog.csdn.net/pi9nc/article/details/9666627
Code(luogu 3382):
1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 #define MN 15 5 #define eps 1e-6 6 using namespace std; 7 inline int in(){ 8 int x=0;bool f=0; char c; 9 for (;(c=getchar())<'0'||c>'9';f=c=='-'); 10 for (x=c-'0';(c=getchar())>='0'&&c<='9';x=(x<<3)+(x<<1)+c-'0'); 11 return f?-x:x; 12 } 13 double a[MN],l,r; 14 int n; 15 inline double check(double x){ 16 double res=0.0; 17 for (int i=0;i<=n;++i) res=res*x+a[i]; 18 return res; 19 } 20 int main() 21 { 22 scanf("%d%lf%lf",&n,&l,&r); 23 for (int i=0;i<=n;++i) scanf("%lf",&a[i]); 24 while (r-l>eps){ 25 double lmid=l+(r-l)/3,rmid=r-(r-l)/3; 26 if (check(lmid)<check(rmid)) l=lmid; 27 else r=rmid; 28 }printf("%.5lf",l);return 0; 29 }