#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#define eps 1e-9
using namespace std;
int r1,r2;
double f(double x){
return 8.0*(sqrt(r1*r1-x*x))*(sqrt(r2*r2-x*x));
}
double simpson(double x,double y){
return (y-x)*(f(x)+f(y)+4*f((x+y)/2))/6.0;
}
double jifen(double x,double y){
double ans=simpson(x,y);//二分区间积分减小误差
double mid=(x+y)/2.0;
double left=simpson(x,mid);
double right=simpson(mid,y);
if(fabs(ans-(left+right))<eps)return ans;
else{
return jifen(x,mid)+jifen(mid,y);
}
}
int main()
{
while(~scanf("%d%d",&r1,&r2)){
if(r1<r2) swap(r1,r2);
double x=1.0*r1;
double y=1.0*r2;
printf("%.4lf\n",jifen(0.0,y));
}
return 0;
}
辛普森积分
最新推荐文章于 2023-09-23 10:50:34 发布