Solution -「P4525」自适应辛普森法

cirnovsky /

题目让我们求:

LRcx+dax+bdx\int_{L}^{R}\frac{cx+d}{ax+b}dx

我记得OJ里TR发过有关自适应辛普森法的帖子,但我没看懂。于是我试着推了一下,就推出了

这样的式子

定义

Fx(x)=x×ca+(dac×ba2×lnx×a+b)F_x(x)=\frac{x\times c}{a}+(\frac{d}{a}-\frac{c\times b}{a^2}\times\mathrm{ln}|x\times a+b|) Fy(x)=x2×cb2+d×xbF_y(x)=\frac{\frac{x^2\times c}{b}}{2} + \frac{d\times x}{b}

LRcx+dax+bdx={Fx(R)Fx(L),a0Fy(R)Fy(L),a=0\int_{L}^{R}\frac{cx+d}{ax+b}dx=\begin{cases} F_x(R)-F_x(L),a\neq 0 \\ \displaystyle F_y(R)-F_y(L),a=0 \end{cases}

代码(极短):

#include <cstdio>
#include <cmath>
#define fx(x) (x * c / a + (d / a - c * b / (a * a)) * log(fabs(x * a + b)))
#define fy(x) (x * x * c / b / 2 + d * x / b)


signed main() {
	long double l, r, a, b, c, d;
    scanf("%Lf %Lf %Lf %Lf %Lf %Lf", &a, &b, &c, &d, &l, &r);
    if (a == 0.0) printf("%.6Lf\n", fy(r) - fy(l));
    else printf("%.6Lf", fx(r) - fx(l));
}