1 //很裸的积分题,直接上模板 2 #include<stdio.h> 3 4 #include<math.h> 5 6 int aa, bb; 7 8 9 //函数 10 double F(double x){ 11 return sqrt((1-x*x/aa/aa)*bb*bb); 12 } 13 14 15 //三点simpson法 16 double simpson(double a,double b){ 17 double c=a+(b-a)/2; 18 return (F(a)+4*F(c)+F(b))*(b-a)/6; 19 } 20 21 22 //自适应simpson公式(递归过程)。一直整个区间[a,b]上的三点simpson值A 23 double asr(double a,double b,double eps,double A){ 24 double c=a+(b-a)/2; 25 double L=simpson(a,c); double R=simpson(c,b); 26 if(fabs(L+R-A)<=15*eps){ 27 return L+R+(L+R-A)/15; 28 } 29 return asr(a,c,eps,L)+asr(c,b,eps,R); 30 } 31 32 33 //自适应simpson公式(主过程) 34 double asr(double a,double b,double eps){ 35 return asr(a,b,eps,simpson(a,b)); 36 } 37 38 int main(){ 39 int t; 40 scanf("%d",&t); 41 while(t--){ 42 int l,r; 43 scanf("%d%d%d%d",&aa,&bb,&l,&r); 44 printf("%.3lf ",asr(l,r,1e-6)*2); 45 } 46 }