Two Cylinders(zju,圆柱交体积)
2013-08-18 09:41
246 查看
http://acm.zju.edu.cn/onlinejudge/showRuns.do?contestId=1
Two Cylinders
Time Limit: 5 Seconds Memory Limit: 32768 KB Special Judge
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.
This problem contains multiple test cases!
The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank line between input blocks.
The output format consists of N output blocks. There is a blank line between output blocks.
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 1
Sample Output
5.3333
解析:给出两个圆柱的半径,求两圆柱相交部分的最大体积。
思路:两圆柱直接正相交即可。这里涉及到辛普森公式,以及一些积分应用
以下是思路来源:
http://blog.csdn.net/wzj792506536/article/details/9418849 http://zh.wikipedia.org/wiki/%E8%BE%9B%E6%99%AE%E6%A3%AE%E7%A9%8D%E5%88%86%E6%B3%95
Author: Andrew Stankevich
Source: Andrew Stankevich's Contest #3
Submit Status
Language Run Time(ms) Run Memory(KB)
2013-07-23 16:40:28 Accepted C++ 0 188
*/
附上:
辛普森法则(Simpson's rule)是一种数值积分方法,是以二次曲线逼近的方式取代矩形或梯形积分公式,以求得定积分的数值近似解。其近似值如下:
该方法系由英格兰人汤马士·辛普森所创立。
简化之公式[编辑]
· h是立体(常指拟柱体)的高度
· a是下底面积
· b是中间截面面积(在一半高度上的截面面积)
· c是上底面积
棱柱和圆柱()
(棱柱和圆柱的体积=底面积*高)
棱锥和圆锥(a=2b,c=0)
(棱锥和圆锥的面积=等底、等高的圆柱、棱柱体积的1/3)
圆台
球体
公式还可以用于计算平面形面积例如:平行四边形、梯形、三角形……
平行四边形(正方形、矩形等)
(平行四边形的面积等于底乘高)
梯形
三角形
Two Cylinders
Time Limit: 5 Seconds Memory Limit: 32768 KB Special Judge
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.
This problem contains multiple test cases!
The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank line between input blocks.
The output format consists of N output blocks. There is a blank line between output blocks.
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 1
Sample Output
5.3333
解析:给出两个圆柱的半径,求两圆柱相交部分的最大体积。
思路:两圆柱直接正相交即可。这里涉及到辛普森公式,以及一些积分应用
以下是思路来源:
http://blog.csdn.net/wzj792506536/article/details/9418849 http://zh.wikipedia.org/wiki/%E8%BE%9B%E6%99%AE%E6%A3%AE%E7%A9%8D%E5%88%86%E6%B3%95
Author: Andrew Stankevich
Source: Andrew Stankevich's Contest #3
Submit Status
Language Run Time(ms) Run Memory(KB)
2013-07-23 16:40:28 Accepted C++ 0 188
*/
#include<stdio.h> #include<string.h> #include<math.h> #include <iostream> using namespace std; const double esp=1e-9; double r1,r2; double f(double x)//横截面的面积计算 { return 4*sqrt(r1*r1-x*x)*sqrt(r2*r2-x*x); } double simpson(double a,double b) { return (b-a)*(f(a)+4*f((a+b)/2)+f(b))/6.0; } double caclulate(double a,double b,int cnt)//这里使计算积分,可是目前还是不大懂为什么这样做??? { double sum=simpson(a,b),mid=(a+b)/2.; double t=simpson(a,mid)+simpson(mid,b); if((fabs(t-sum)<esp)&& cnt>3) return sum; return caclulate(a,mid,cnt+1)+caclulate(mid,b,cnt+1); } int main() {int T; double r,ans; scanf("%d",&T); while(T--) { scanf("%lf%lf",&r1,&r2); if(r1-r2>esp)//这里的比较大小与精度有关 r=r2; else r=r1; ans=2.0*caclulate(0,r,0); printf("%.4lf\n",ans); } return 0; }
附上:
辛普森法则(Simpson's rule)是一种数值积分方法,是以二次曲线逼近的方式取代矩形或梯形积分公式,以求得定积分的数值近似解。其近似值如下:
该方法系由英格兰人汤马士·辛普森所创立。
简化之公式[编辑]
· h是立体(常指拟柱体)的高度
· a是下底面积
· b是中间截面面积(在一半高度上的截面面积)
· c是上底面积
棱柱和圆柱()
(棱柱和圆柱的体积=底面积*高)
棱锥和圆锥(a=2b,c=0)
(棱锥和圆锥的面积=等底、等高的圆柱、棱柱体积的1/3)
圆台
球体
公式还可以用于计算平面形面积例如:平行四边形、梯形、三角形……
平行四边形(正方形、矩形等)
(平行四边形的面积等于底乘高)
梯形
三角形
相关文章推荐
- 求圆柱体积
- 实验三-计算圆柱体积
- 圆柱体积
- 求圆柱的体积
- 圆柱体积
- 圆柱的体积
- 12--7圆柱体积和面积(有点难度)
- 圆柱体积
- 【HDU】5060 War 求圆柱和圆的体积交与体积并
- 【c语言】设圆半径r = 1.5,圆柱高h = 3,求圆周长,圆面积,圆球表面积,圆球体积,圆柱体积
- 圆柱体积
- 设半径r=1.5,圆柱高h=3,求圆周长、圆面积、圆球表面积、圆球体积、圆柱体积。
- hdu 5060 求球与圆柱相交体积
- poj 3365 数学分类(最大的圆柱体积)
- 圆柱体积
- zoj 1904 Beavergnaw 计算圆柱和圆台的体积
- (c++)设圆半径r,圆柱高h 求圆周长C1、圆面积Sa、圆球表面积Sb、圆球体积Va、圆柱体积Vb。 用scanf输入数据,输出计算结果,输出时要求文字说明,取小数点后两位数字。请编程序。 PI=3
- 圆柱体积
- 计算圆,球,圆锥,圆柱的表面积与体积
- 几何题-求圆柱最大体积