傳送門
Two Cylinders
Special Judge Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others)
Submit Statistic Next Problem
Problem Description
In this problem your task is very simple.
Consider two infinite cylinders in three-dimensional space, of radii R1 and R2 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 R1 and R2 (1 <= R1,R2 <= 100).
Output
Output the volume of the intersection of the cylinders. Your answer must be accurate up to 10⑷.
Sample Input
1 1
Sample Output
5.3333
Source
Andrew Stankevich Contest 3
Manager
mathlover
題目大意:
給了兩個圓柱的半徑 r1,r2,他們的軸線垂直相交,讓你求的是相交部份的體積。
解題思路:
這個題目首先我們對其積分:得到1個公式:
/**
求兩個交叉圓柱的體積
**/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
const double eps = 1e⑼;///精度
using namespace std;
double 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)///積分區間[x,y]
{
double ans = simpson(x,y);///2分區間積分減小誤差
double mid = (x+y)/2.0;
double left = simpson(x,mid);
double right = simpson(mid,y);
if(fabs(ans-(left+right)) < eps)
return ans;
return jifen(x,mid)+jifen(mid,y);
}
int main()
{
while(~scanf("%lf%lf",&r1,&r2))
{
if(r1<r2) swap(r1,r2);
printf("%.6lf\n",jifen(0.0,r2));
}
return 0;
}