Given the values of r, r1, r2 and r3 you will have to find the area of triangle ABC.
Input is terminated by a line containing four negative integers.
For each line of input produce one line of output. This line contains serial of output followed by a floating-point number which denotes the area of triangle ABC. This floating-point number may have two digits after the decimal point. You can assume that for the given values of r, r1, r2 and r3 it will always be possible to construct a triangle ABC. If required you can assume that pi = 3.141592653589793 and also use double precision floating-point numbers for floating-point calculations. You can assume that there will be no such input for which small precision errors will cause difference in printed output. Look at the output for sample input for details.
49.1958415692 5.3025839959 20.7869367050 31.8019699761 186.6830516757 71.9474500429 84.8796672233 37.6219288070 -1 -1 -1 -1
Case 1: 18237.14 Case 2: 195777.32
思路:
#includeusing namespace std; double r[5]; double fun(double r1,double r2) { return ((r1+r2)*(r1+r2)-(r1-r2)*(r1-r2)); } bool cmp(double p1,double p2) { return p1>p2; } int main() { int d=1; while (~scanf("%lf%lf%lf%lf",&r[0],&r[1],&r[2],&r[3]) && r[0]!=-1) { sort(r,r+4,cmp); // for (int i=0;i<4;i++) // printf("%lf ",r[i]); // printf("\n"); double a1 = sqrt(fun(r[0],r[1])); double x1 = (a1*r[1]*1.0)/(r[0]-r[1]); double a2 = sqrt(fun(r[0],r[2])); double x2 = (a2*r[2]*1.0)/(r[0]-r[2]); double a3 = sqrt(fun(r[0],r[3])); double x3 = (a3*r[3]*1.0)/(r[0]-r[3]); double aa1=(a1+x1)+(a2+x2),aa2=(a2+x2)+(a3+x3),aa3=(a1+x1)+(a3+x3); double q=(aa1+aa2+aa3)/2.0; double s= sqrt(q*(q-aa1)*(q-aa2)*(q-aa3)); printf("Case %d: %.2lf\n",d++,s); } return 0; }