辛普森法:
然后自适应??
只要判断左右辛普森法合并和当前区间辛普森法误差是否较小就好了1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
using namespace std;
typedef double db;
double a, b, c, d, l, r;
inline db F(db x) {
return (c * x + d) / (a * x + b);
}
inline db simpson(db l, db r) {
return (F(l) + F(r) + 4 * F((l + r) / 2)) * (r - l) / 6;
}
db work(db l, db r, db eps, db a) {
db mid = (l + r) / 2;
db _l = simpson(l, mid), _r = simpson(mid, r);
if(abs(_l + _r - a) <= 15 * eps) return _l + _r;
return work(l, mid, eps / 2, _l) + work(mid, r, eps / 2, _r);
}
inline db integral(db l, db r, db eps) {
if(l == r) return 0;
if(l > r) return work(r, l, eps, simpson(r, l));
return work(l, r, eps, simpson(l, r));
}
int main() {
scanf("%lf%lf%lf%lf%lf%lf", &a, &b, &c, &d, &l, &r);
return printf("%.6f\n", integral(l, r, 1e-6)), 0;
}