sgu 217. Two Cylinders 积分

217. Two Cylinders
time limit per test: 0.5 sec.
memory limit per test: 65536 KB
input: standard
output: standard



In this problem your task is very simple. 

Consider two infinite cylinders in three-dimensional space, of radii R 1 and R 2 respectively, located in such a way that their axes intersect and are perpendicular. 

Your task is to find the volume of their intersection. 

Input

Input file contains two real numbers R 1 and R 2 (1 ≤ R 1, R 2 ≤ 100); 

Output

Output the volume of the intersection of the cylinders. Your answer must be accurate up to 10 -4

Sample test(s)

Input
 
1 1 
Output
 
  
5.3333 

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;


double r1, r2;

double f(double x){
    return sqrt((r1*r1-x*x)*(r2*r2-x*x));//写要求辛普森积分的函数
}

double simpson(double L, double R){//三点辛普森积分法,要求f(x)是全局函数
    double mid = (L + R) / 2.0;
    return (f(L) + 4.0 * f(mid) + f(R)) * (R - L) / 6.0;
}

double integral(double L, double R, double Eps){//自适应辛普森积分递归过程
    double mid = (L + R) / 2.0;
    double ST = simpson(L, R), SL = simpson(L, mid), SR = simpson(mid, R);
    if(fabs(SL + SR - ST) <= 15.0 * Eps)  return SL + SR + (SL + SR - ST) / 15.0;//直接返回结果
    return integral(L, mid, Eps/2.0) + integral(mid, R, Eps/2.0);//对半划分区间
}
int main()
{
    cin>>r1>>r2;
    printf("%lf",integral(0,min(r1,r2),1e-4)*8);
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值