今日头条杯 2018 年首届湖北省大学生程序设计竞赛 (网络赛)Problem B.(计算几何)

Problem B. 

GSS and Interesting SculptureInput file: standard inputOutput file: standard outputTime limit: 1 secondsMemory limit: 512 mebibytesGSS is painting an strange sculpture, the sculpture contests of two balls and they may intersect. Your task is tocalculate the area of the surface of the sculpture.InputInput contains multiple cases, please process to the end of input.For each line, there are three integers, R, r, L, R and r the radius of the two balls, L is the distance of the centerof two balls.0 < R, r, L ≤ 100, |R − r| < L ≤ |R + r|OutputFor each input, output one line with the answer, the area of the surface of the sculpture. Let the standard answerbe a, and your answer be b, your answer will be considered as correct if and only if |a−b|max(a,1) < 10−6.Examples

standard input                   standard output

         3 4 5                          271.433605270158

         3 3 3                          169.646003293849

         1 2 3                           62.831853071796

题意:两个球相交 , 已知 r , R , L . L为两圆的圆心距 ,求两圆相交后组成的物体的表面积。

思路:S = 圆1的表面积 + 圆2的表面积 - 圆1相交部分的球冠表面积 - 圆2相交部分的球冠表面积

在这里引用球冠表面积的求法:

若球半径是R,球冠的高是h,球冠面积是S,则S=2πRh,若球冠的底的半径是r,则S=π(r^2+h^2)。


利用微积分原理推导公式

上式中可以推出:x = (r^2 - R^2 + L^2)/2*L ;

h1 = r-x;

h2 = R-L-x;

 将h1 , h2 带入公式即可得;

下面代码:

#include<stdio.h>
const double pi = 3.141592653589793238;
int main()
{
	double R,r,L;
	while(~scanf("%lf %lf %lf",&r, &R, &L))
	{
	if(r +R > L)
	{
		double x = (r * r - R*R + L*L) / (2.0 * L);
		double s1 = 4 * pi *r *r;
		double s2 = 4 * pi * R *R;
		double S = s1+ s2;
		double h1 = r - x;
		double h2 =R-(L -x);
		double res = S - 2 * pi *r*h1 - 2*pi*R*h2;
		printf("%.12lf\n",res);
	}
	else
	{
		double s1 = 4 * pi *r *r;
		double s2 = 4 * pi * R *R;
		double S = s1+ s2;
		printf("%.12lf\n",S);
	}

}
	
	
	return 0;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值