欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Problem B. GSS and Interesting Sculpture

程序员文章站 2022-06-08 08:35:28
...

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;

Problem B. GSS and Interesting Sculpture

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

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