# 今日头条杯 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

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