acdream 1234-Two Cylinders(辛普森积分)
2017-10-19 13:45
176 查看
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-4.
Sample Input
1 1
Sample Output
5.3333
Source
题意:给你两个半径不同的圆柱体,计算垂直相交的体积
题解:当半径相同时,大一高数中学过,相交的体积为:16/3*R^3
当半径不相同时:
这里我们采用辛普森积分来进行积分(否则会越积越复杂)
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
using namespace std;
const double eps = 1e-10;
const double PI = acos(-1.0);
double r1,r2;
double f(double x)
{
return sqrt((r1*r1-x*x)*(r2*r2-x*x));
}
double simpson(double a,double b)
{
double c=a+(b-a)/2;
return (f(a)+4*f(c)+f(b))*(b-a)/6;
}
double asr(double a,double b) ///迭代求解数值积分
{
double mid=(a+b)/2.0;
double res=simpson(a,b);
if(fabs(res-simpson(a,mid)-simpson(mid,b))<eps)
{
return res;
}
else return asr(a,mid)+asr(mid,b);
}
int main(void)
{
while(scanf("%lf%lf",&r1,&r2)!=EOF)
{
if(r1==r2)
printf("%.4lf\n",16.0/3*r1*r1*r1);
else
{
if(r1>r2)
swap(r1,r2);
printf("%.4lf\n",8.0*asr(0,r1));
}
}
return 0;
}
相关文章推荐
- Acdream 1234 Two Cylinders(自适应辛普森积分法)
- SGU 217 Acdream 1234 Two Cylinders 自适应辛普森
- ZOJ 2369 | SGU 217 | Acdream 1234 自适应辛普森积分
- zoj 2369 Two Cylinders 辛普森积分 几何
- acdream 1234 Two Cylinders
- 数值积分 (辛普森公式 辛普森自适应法则) UVA
- sgu217:Two Cylinders(simpson积分)
- 自适应辛普森积分
- 自适应辛普森法求积分
- bzoj 2178 圆的面积并【辛普森积分】
- [BZOJ1502][NOI2005]月下柠檬树(辛普森积分)
- SPOJ-CIRU 多圆并面积(计算几何-辛普森积分)
- HDU 1724 Ellipse (自适应辛普森积分模板题)
- 自适应辛普森积分
- 自适应辛普森法求积分
- hdu 1724 辛普森积分公式
- 变步长辛普森求数值积分
- HDU 1724 辛普森积分公式
- 自适应辛普森法求积分
- BZOJ 1502 NOI 2005 月下柠檬树 计算几何 自适应辛普森积分