程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> 關於C++ >> In

In

編輯:關於C++

In-circles Again

Time Limit: 1000ms Memory Limit: 65536KB 64-bit integer IO format: %lld Java class name: Main Submit Status PID: 4272 In the figure below you can see triangle ABC and its in-circle (Circle that touches all the sides of a triangle internally). The radius of this in circle is r. Three other circles are drawn. Each of them touches two sides of this triangle and the in circle of ABC. The radiuses of these circles are r1, r2 and r3. \

Given the values of r, r1, r2 and r3 you will have to find the area of triangle ABC.

Input

The input file can contain up to 1000 lines of inputs. Each line contains four positive floating-point numbers which denotes the values of r, r1, r2 and r3 respectively.

Input is terminated by a line containing four negative integers.

Output

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.

Sample Input

49.1958415692 5.3025839959 20.7869367050 31.8019699761
186.6830516757 71.9474500429 84.8796672233 37.6219288070
-1 -1 -1 -1

Sample Output

 


Case 1: 18237.14
Case 2: 195777.32

思路:
#include using 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; }

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved