hdu 1724 Ellipse——辛普森积分

时间:2024-01-16 22:55:56

题目:http://acm.hdu.edu.cn/showproblem.php?pid=1724

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define db double
using namespace std;
const db eps=1e-;
int T;db a,b,l,r;
db f(db x){return sqrt((-x*x/a)*b);}
db cal(db l,db r){return (f(l)+*f((l+r)/)+f(r))*(r-l)/;}
db simp(db l,db r,db eps,db ret)
{
db mid=(l+r)/,vl=cal(l,mid),vr=cal(mid,r);
if(fabs(vl+vr-ret)<=*eps)return vl+vr+(vl+vr-ret)/;//not ret+()/15
return simp(l,mid,eps/,vl)+simp(mid,r,eps/,vr);
}
int main()
{
scanf("%d",&T);
while(T--)
{
scanf("%lf%lf%lf%lf",&a,&b,&l,&r);
a*=a;b*=b;
printf("%.3lf\n",simp(l,r,eps,cal(l,r))*);
}
return ;
}