struct Simpson
{
static const double eps=1e-8;
static double f(double x)
{
return (c*x+d)/(a*x+b);
}
double simpson(double l,double r)
{
return (r-l)*(f(l)+f(r)+4*f((l+r)/2))/6;
}
double integral(double l,double r,double ans=1e18)
{
double mid=(l+r)/2;
double le=simpson(l,mid),ri=simpson(mid,r);
if(fabs(le+ri-ans)<eps)return le+ri;
return integral(l,mid,le)+integral(mid,r,ri);
}
}S;
网友评论