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

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 }

 

转载于:https://www.cnblogs.com/Carered/p/11406692.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值