P4525 模板自适应辛普森法1
Posted wstong
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了P4525 模板自适应辛普森法1相关的知识,希望对你有一定的参考价值。
1 #include <bits/stdc++.h> 2 using namespace std; 3 const double eps = 1e-6; 4 double a, b, c, d, l, r; 5 inline double f(double x) { 6 return (c*x+d)/(a*x+b); 7 } 8 inline double simpson(double l, double r) { 9 double mid = (l+r)/2; 10 return (f(l)+4*f(mid)+f(r))*(r-l)/6; 11 } 12 inline double asr(double l, double r, double eps, double ans) { 13 double mid = (l+r)/2; 14 double ll = simpson(l,mid), rr = simpson(mid,r); 15 if (fabs(ll+rr-ans) <= 15*eps) return ll+rr+(ll+rr-ans)/15; 16 return asr(l,mid,eps/2,ll)+asr(mid,r,eps/2,rr); 17 } 18 inline double asr(double l, double r, double eps) { 19 return asr(l,r,eps,simpson(l,r)); 20 } 21 int main() { 22 scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&l,&r); 23 printf("%.6f",asr(l,r,eps)); 24 return 0; 25 }
以上是关于P4525 模板自适应辛普森法1的主要内容,如果未能解决你的问题,请参考以下文章