hdu 1724 Ellipse——辛普森积分
题目: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-5; int T;db a,b,l,r; db f(db x){return sqrt((1-x*x/a)*b);} db cal(db l,db r){return (f(l)+4*f((l+r)/2)+f(r))*(r-l)/6;} db simp(db l,db r,db eps,db ret) { db mid=(l+r)/2,vl=cal(l,mid),vr=cal(mid,r); if(fabs(vl+vr-ret)<=15*eps)return vl+vr+(vl+vr-ret)/15;//not ret+()/15 return simp(l,mid,eps/2,vl)+simp(mid,r,eps/2,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))*2); } return 0; }