Two Cylinders (辛普森公式处理积分)
来源:互联网 发布:网络的英文翻译 编辑:程序博客网 时间:2024/05/16 18:03
Two Cylinders (辛普森公式处理积分):http://acm.hust.edu.cn/vjudge/contest/view.action?cid=120113#problem/I 传送门:nefu
题面描述:
I - Two Cylinders
Time Limit:1000MS Memory Limit:64000KB 64bit IO Format:%lld & %lluDescription
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 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 Input
1 1
Sample Output
5.3333
题目大意:
此题要计算两个圆柱体垂直相交之后形成的体积,且两个圆柱体的半径不一样。
题目分析:
可以先依据两个半径相等的圆柱体相交所得物体(称为:牟合方盖)的体积计算方法来推导半径不相等的物体的体积,计算牟合方盖的体积时,我们都是利用定积分,先计算在第一卦限中的体积,最后乘以8就行了,具体过程如下。
求解两柱体x2+y2=R2和x2+z2=R2相交部分的体积。
而此题所要求的是柱体x2+y2=R22和x2+z2=R12相交的体积。
我们同样也是只算第一卦限的体积,最后乘以8即可。
代码实现如下:
#include <iostream>#include <cstdio>#include <cmath>using namespace std;const double esp=1e-10;double r1,r2;double f(double x){ return sqrt((r1*r1-x*x)*(r2*r2-x*x));}double Simpson(double a,double b) { return (b-a)*(f(a)+f(b)+4*f((a+b)/2.0))/6.0;}double Midd(double a,double b) ///迭代求解数值积分{ double mid=(a+b)/2.0; double res=Simpson(a,b); if(fabs(res-Simpson(a,mid)-Simpson(mid,b))<esp) { return res; } else return Midd(a,mid)+Midd(mid,b);}int main(){ while(scanf("%lf%lf",&r1,&r2)!=EOF) { if(r1==r2) printf("%.4lf\n",16.0/3*r1*r1*r1); else { if(r1>r2) { double t=r1; r1=r2; r2=t; } printf("%.4lf\n",8.0*Midd(0,r1)); } } return 0;}
0 0
- Two Cylinders (辛普森公式处理积分)
- acdream 1234-Two Cylinders(辛普森积分)
- Acdream 1234 Two Cylinders(自适应辛普森积分法)
- sgu217:Two Cylinders(simpson积分)
- 【数值积分】 ZOJ 2369 Two Cylinders
- acdream 1234 Two Cylinders
- sgu-217 Two Cylinders
- 辛普森积分(自适应辛普森公式求积分)
- SGU 217 Acdream 1234 Two Cylinders 自适应辛普森
- 自适应辛普森公式求积分
- HDU 1724 辛普森积分公式
- hdu 1724 辛普森积分公式
- 积分公式
- Two Cylinders(zju,圆柱交体积)
- hdu 1724 辛普森公式求积分
- hdu 1724数学题 辛普森公式求积分
- LA 3485 辛普森公式求积分
- 自适应辛普森公式求积分模板
- Servlet 注册01
- Leetcode-maximum-depth-of-binary-tree
- Eclipse插件springsource-tool-suite的下载和安装
- 学习 Promise (结合 Rxjava)
- Leetcode-reverse-integer
- Two Cylinders (辛普森公式处理积分)
- 二叉树的遍历。。。
- BZOJ 2208: [Jsoi2010]连通数
- 4. gpio 库
- Android Studio NDK调试(基于gradle-experimental插件与LLDB)
- jquery 基础
- Linux内核模块编译
- The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path的解决办法
- Android: 动画实现雷达效果