码迷,mamicode.com
首页 > 其他好文 > 详细

In-circles Again(简单几何)

时间:2015-04-19 21:27:54      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:数学   几何   

In-circles Again

Time Limit: 1000ms
Memory Limit: 65536KB
64-bit integer IO format: %lld      Java class name: Main
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<bits/stdc++.h>
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;
}

In-circles Again(简单几何)

标签:数学   几何   

原文地址:http://blog.csdn.net/u012349696/article/details/45131767

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!