P4525 【模板】自适应辛普森法1

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 }

 

posted @ 2019-11-01 19:27  麻辣猪仔  阅读(142)  评论(0编辑  收藏  举报