Problem B. GSS and Interesting Sculpture

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 ;球可以重叠成一个形状,求这个物体的表面积。

S为灰色部分的球体表面积,由下式得出球体部分表面积公式:S=2*pi*R*H;


求出两球表面积,减去各球重叠部分的表面积。

#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
#define maxn 805
#include<queue>
#include<deque>
#include<map>
const double pi=3.141592653589793238;
typedef long long ll;
using namespace std;
int main()
{
    double r,R,l;
    while(~scanf("%lf%lf%lf",&r,&R,&l))
    {
        if(r+R>l){
        double x=(r*r+l*l-R*R)/(2.0*l);
        double h1=r-x;
        double h2=R-(l-x);
        double s1=4*pi*r*r;
        double s2=4*pi*R*R;
        double s=s1+s2;
        double ss1=2*pi*r*h1;
        double ss2=2*pi*R*h2;
        printf("%.12lf\n",s-ss1-ss2);
        }
        else
        {
          double s1=4*pi*r*r;
          double s2=4*pi*R*R;
          printf("%.12lf\n",s1+s2);
        }
    }
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值