洛谷3382
1 #include<iostream> 2 #include<cstring> 3 #include<cstdlib> 4 #include<cstdio> 5 #include<cmath> 6 #include<algorithm> 7 using namespace std; 8 const int maxn=15, inf=1e9; 9 int n; 10 double l,r,a[maxn]; 11 double f(double x){ 12 double ans=0, now=1; 13 for(int i=n+1;i;i--) ans+=now*a[i], now*=x; 14 return ans; 15 } 16 int main(){ 17 scanf("%d%lf%lf",&n,&l,&r); 18 for(int i=1;i<=n+1;i++) scanf("%lf",&a[i]); 19 while(r-l>1e-6){ 20 double mid1=l+(r-l)/3, mid2=l+(r-l)/3*2; 21 if(f(mid1)>f(mid2)) r=mid2; 22 else l=mid1; 23 } 24 printf("%.5lf",l); 25 }