Two Cylinders(zju,圆柱交体积)

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

*/

#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)

圆台

球体

公式还可以用于计算平面形面积例如:平行四边形、梯形、三角形……

平行四边形(正方形、矩形等)

(平行四边形的面积等于底乘高)

梯形

三角形

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值