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 )
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;
}