2300: We Share a Wireless Route(费马点)

Result TIME Limit MEMORY Limit Run Times AC Times JUDGE
3s 8192K 143 52 Standard

Parhelic, codger and I are good friends. As we know, the educational net can not access to foreign websites. As a result, we can't go to acm.uva.es to solve problems. So we decided to find a way to share a CNC net. We three lived in different rooms, but luckily enough, we each had a laptop computer with wireless module. So we bought a wireless route. After reading the introduction of the route, we knew that the position to set the route is quite a problem.

There is a distance limit D of the wireless route. PR, CR, LR represents the distance from Parhelic, Codger, I to the Route respectively. PR+CR+LR cannot be bigger than D, or the signal will be quite unstable. So we had to calculate the minimum possible sum of PR, CR and LR. Obviously, Parhelic, codger and I are three vertex of a triangle(our rooms are not in a straight line). We only got the length of the three edges of the triangle and began to solve the problem. Can you do us a favor?

Input

There will be several test cases. Each test case gives you three positive intergers a, b and c, represents the length of an edge respectively. It is guaranteed that a<=b<=c and they can compose of a triangle.

Output

Find out the best place for the route and output the minimum sum of PR, CR and LR in one line per test case(accurate to 0.001).

Sample Input

3 4 5
10 10 10
4 5 8

Sample Output

6.766
17.321
9.000
/*
| 三角形几个重要的点
| INIT: pnt[]已按顺时针(或逆时针)排好序;
| CALL: res = bcenter(pnt, n);
设三角形的三条边为a, b, c,且不妨假设a <= b <= c,
三角形的面积可以根据海伦公式算得,如下:
s = sqrt(p * (p - a) * (p - b) * (p - c));
p = (a + b + c) / 2;
下面是计算该点到三角形三个顶点A,B,C的距离之和

1. 费马点(该点到三角形三个顶点的距离之和最小)
   有个有趣的结论:若三角形的三个内角均小于120度,那么该点连接
三个顶点形成的三个角均为120度;若三角形存在一个内角大于120度,
则该顶点就是费马点)计算公式如下:
若有一个内角大于120度(这里假设为角C),则距离为a + b
若三个内角均小于120度,则距离为
sqrt((a * a + b * b + c * c + 4 * sqrt(3.0) * s) / 2),其中

2. 内心----角平分线的交点
   令x = (a + b - c) / 2, y = (a - b + c) / 2,
     z = (-a + b + c) / 2, h = s / p. 计算公式为
sqrt(x*x + h*h) + sqrt(y*y + h*h) + sqrt(z * z + h * h)

3. 重心----中线的交点, 计算公式如下:
   2.0 / 3 * (sqrt((2 * (a * a + b * b) - c * c) / 4)
          + sqrt((2 * (a * a + c * c) - b * b) / 4)
          + sqrt((2 * (b * b + c * c) - a * a) / 4))

4. 垂心----垂线的交点, 计算公式如下:
   3 * (c / 2 / sqrt(1 - cosC * cosC))

*/
#include <cstdio>
#include <iostream>
#include <cmath>
//#include <>
using namespace std;
const double pi=acos(-1.);
double s (double a,double b,double c)
{
    double p=(a+b+c)/2;
    return sqrt(p*(p-a)*(p-b)*(p-c));
}
int main ()
{
    double a,b,c;
    while (scanf("%lf%lf%lf",&a,&b,&c)!=EOF)
    {
        double tmp=(a*a+b*b-c*c)/(2*a*b),ans;
        tmp=acos(tmp);
        if(tmp>=pi*2/3)
        {
            ans=a+b;//
        }
        else
        {
            ans=sqrt((a * a + b * b + c * c + 4 * sqrt(3.0) * s(a,b,c)) / 2);
        }//公式 要记住!(虽然不知道怎么来的)
        printf("%.3lf/n",ans);
    }
    return 0;
}

你可能感兴趣的:(2300: We Share a Wireless Route(费马点))