自适应simpson积分公式
通过二分区间递归求simpson积分
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<map> #include<set> #include<cmath> #include<queue> #include<stack> #include<vector> #include<cstdio> #include<cassert> #include<iomanip> #include<cstdlib> #include<cstring> #include<iostream> #include<algorithm> #define pi acos(-1) #define ll long long #define mod 1000000007 #define ls l,m,rt<<1 #define rs m+1,r,rt<<1|1 #pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; const double g=10.0,eps=1e-9; const int N=10+10,maxn=100000+10,inf=0x3f3f3f; double v1,v2,k,x; double f(double t) { return k/(v1*v1*t*t+(x-v2*t)*(x-v2*t)); } double simpson(double l,double r) { return (f(l)+4*f((l+r)/2)+f(r))*(r-l)/6; } double solve(double l,double r) { double m=(l+r)/2.0; double res=simpson(l,r); if(fabs(res-simpson(l,m)-simpson(m,r))<eps)return res; else return solve(l,m)+solve(m,r); } int main() { ios::sync_with_stdio(false); cin.tie(0); cout<<setiosflags(ios::fixed)<<setprecision(2); int t; cin>>t; while(t--){ cin>>v1>>v2>>x>>k; cout<<solve(0,1e18)<<endl; } return 0; }