HDU 3310-Volume of a cylinder(积分)

Description

One cylinder across another cylinder at right angles, tell the volume of the intersection of the cylinders.

Input

Multiple test cases, the number of them T is given in the very first line. 
For each test case, two integers r1 and r2, meaning the radius of the two cylinders. ( 1 < r1, r2 < 80 )

Output

For each case, output the answer rounded to 2 digits after the decimal point. 

Sample Input

1
4 4

Sample Output

341.33
给两个圆柱的半径,两个圆柱垂直相交,让你求相交部分的面积。 利用积分,具体解释看代码注释:

/*
两圆柱相交放到空间坐标系中,由对称只看第一象限,在xoy面,投影为半径为r1(始终让r1<r2,画图看看为什么)的1/4圆;
积分区域:0<<y<<根号下(r1^2-x^2); 0<<x<<r1,积分方程 : z=根号下(r2^2-x^2);
化简后等于,求 根号下(r1^2-x^2)*(r2^2-x^2)dx积分上下限为0,r1;-----但是妈的化简不出来,所以就用微分化成很多的小区间来做,
需要注意每次增加dx的时候取两个小区间的平均值。
*/
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <stack>
#include <vector>
#include <queue>
#include <string>
#include <iostream>
#include <cmath>
#define mod 1000000
using namespace std;
double fun(double x,double r1,double r2)
{
    return sqrt((double)r1*r1-x*x)*sqrt((double)r2*r2-x*x);

}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int r1,r2;
        cin>>r1>>r2;
        if(r1>r2)
            swap(r1,r2);
        double v1=0;
        double dx=r1/(mod * 1.0);
        for(int i = 0;i < mod;i++)
        {
            v1+=fun(dx*i+0.5*dx,(double)r1,(double)r2);
        }
        double v=v1*8*dx;
        printf("%.2lf\n",v);
    }
    return 0;
}






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值