洛谷.4525.[模板]自适应辛普森法1(Simpson积分)
Simpson积分公式:$$\int_a^bf(x)dx\approx\frac{b-a}{6}\left[f(a)+f(b)+4f(\frac{a+b}{2})\right]$$
推导过程大概就是,令\(f(x)=Ax^2+Bx+C\),代进去求一下积分就好了?
自适应是指根据区间大小控制精度。满足精度要求时直接返回。
那个,有人知道asr
是指什么吗。。(什么的缩写?)
//0ms 1.7MB
#include <cmath>
#include <cstdio>
#include <algorithm>
#define eps (1e-6)
double a,b,c,d,L,R;
inline double f(double x){
return (c*x+d)/(a*x+b);
}
inline double Simpson(double l,double r){
return (r-l)*(f(r)+f(l)+4*f((l+r)*0.5))/6.0;
}
double asr(double l,double r,double Eps,double ans)
{
double mid=(l+r)*0.5, lans=Simpson(l,mid), rans=Simpson(mid,r);
if(fabs(lans+rans-ans)<Eps) return lans+rans;
return asr(l,mid,Eps*0.5,lans)+asr(mid,r,Eps*0.5,rans);
}
int main()
{
scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&L,&R);
printf("%.6lf",asr(L,R,eps,Simpson(L,R)));
return 0;
}
------------------------------------------------------------------------------------------------------------------------
很久以前的奇怪但现在依旧成立的签名
attack is our red sun $$\color{red}{\boxed{\color{red}{attack\ is\ our\ red\ sun}}}$$ ------------------------------------------------------------------------------------------------------------------------
很久以前的奇怪但现在依旧成立的签名
attack is our red sun $$\color{red}{\boxed{\color{red}{attack\ is\ our\ red\ sun}}}$$ ------------------------------------------------------------------------------------------------------------------------