UVA - 10347 - Medians(由三中线求三角形面积)

社会主义新天地 提交于 2019-11-28 11:31:53

AC代码:

 1 #include<cstdio>
 2 #include<cmath>
 3 #include<algorithm>
 4 #include<iostream>
 5 #include<cstring>
 6 using namespace std;
 7 typedef long long ll;
 8 const double eps = 1e-8;
 9 int sgn(double x)
10 {
11     if(fabs(x) < eps) return 0;
12     else return x < 0 ? -1 : 1;
13 }
14 int main()
15 {
16     double a, b ,c;
17     while(~scanf("%lf %lf %lf",&a,&b,&c))
18     {
19         if(a!=0 && b != 0 && c != 0 && sgn(a + b - c) > 0&& sgn( a + c - b ) > 0 &&sgn( b + c - a) > 0)
20         {
21             double p =a + b + c;
22             double Elem1 = p -2*a;
23             double Elem2 = p -2*b;
24             double Elem3 = p -2*c;
25             double S=sqrt(p *Elem1*Elem2*Elem3);
26             S/=3;
27             printf("%.3f\n",S);
28         }
29         else
30            printf("-1.000\n");
31     }
32     return 0;
33 }

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!