文章目錄
- Input
- Output
- Sample Input
- Sample Output
| 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;
}