UVA-10347 Medians 计算几何 中线定理

题面

题意:已知三角形三中线的长度nmp,求面积

题解:如果知道中线定理就比较简单了

        三边长为 3*a=sqrt(8*mb*mb+8*mc*mc-4*ma*ma) 

                       3*b=sqrt(8*ma*ma+8*mc*mc-4*mb*mb)

                       3*c=sqrt(8*ma*ma+8*mb*mb-4*mc*mc) 再利用海伦s=sqrt( p*(p-a)*(p-b)*(p-c) ); p=(a+b+c)/2;

         所以 s=sqrt( t*(t-2*p)*(t-2*n)*(t-2*m ) ) / 3;               t=n+m+p;     别忘了判三角形是否存在(三中线的长度关系和三边一样,两边和大于另一边) 

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 double t,s,n,m,p;
 4 int why;
 5 int main()
 6 {
 7     while (cin>>n>>m>>p)
 8     {
 9         if (n<=0 || m<=0 || p<=0)
10         {
11             printf("-1.000\n");
12             continue;
13         }     
14         why=0;
15         if (n+m>p) why++;
16         if (n+p>m) why++;
17         if (m+p>n) why++;
18         if (why!=3)
19         {
20             printf("-1.000\n");
21             continue;
22         } 
23         t=n+m+p;
24         s=t*(t-2*p)*(t-2*n)*(t-2*m);
25         if (s<0) printf("-1.000\n");else printf("%.3lf\n",sqrt(s)/3);
26     }
27 }

猜你喜欢

转载自www.cnblogs.com/qywhy/p/9772423.html