以后再来研究为啥是这样,先存个模板
https://www.luogu.org/problemnew/show/P4525
注意把需要的精度缩小两倍,区间不能过大,有时需要推导或者画图。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double eps=1e-8;
double a,b,c,d,L,R;
//需要积分的函数
double F(double x)
{
return (c * x + d) / (a * x + b);
}
double simpson(double l,double r)
{
double mid=(l+r)/2;
return (F(l)+4*F(mid)+F(r))*(r-l)/6;
}
double asr(double l,double r,double A)
{
double mid=(l+r)/2;
double L=simpson(l,mid),R=simpson(mid,r);
if(fabs(L+R-A)<=15*eps) return L+R+(L+R-A)/15.0;
return asr(l,mid,L)+asr(mid,r,R);
}
double asr(double l,double r){return asr(l,r,simpson(l,r));}
int main()
{
ios::sync_with_stdio(0); cin.tie(0);
cin >> a >> b >> c >> d >> L >> R;
cout << fixed << setprecision(6) << asr(L, R, 1e-8) << endl;
return 0;
}