
题目描述
计算积分
结果保留至小数点后6位。
数据保证计算过程中分母不为0且积分能够收敛。
输入输出格式
输入格式:
一行,包含6个实数a,b,c,d,L,R
输出格式:
一行,积分值,保留至小数点后6位。
输入输出样例
说明
a,b,c,d∈[-10,10]
-100≤L<R≤100 且 R-L≥1
辛普森积分是用$y = Ax^2 +Bx +c$去拟合给定的函数
$$\int_a^bf(x)dx\approx\frac{(b-a)(f(a)+f(b)+4f(\frac{a+b}{2}))}{6}$$
自适应的含义是根据不同的区间大小选用不同的eps
// luogu-judger-enable-o2
#include<cstdio>
#include<cmath>
double a, b, c, d, L, R;
double F(double x) {
return (c * x + d) / (a * x + b);
}
double sim(double l, double r) {
return (F(l) + F(r) + * F((l + r) / )) * (r - l) / ;
}
double asr(double L, double R, double eps, double ans) {
double mid = (L + R) / ;
double LL = sim(L, mid), RR = sim(mid, R);
if(fabs(LL + RR - ans) < eps) return LL + RR;
else return asr(L, mid, eps / , sim(L, mid)) + asr(mid, R, eps / , sim(mid, R));
}
main() {
#ifdef WIN32
freopen("a.in", "r", stdin);
#endif
scanf("%lf %lf %lf %lf %lf %lf", &a, &b, &c, &d, &L, &R);
printf("%lf", asr(L, R, 1e-, sim(L, R)));
}