zoukankan      html  css  js  c++  java
  • UVA 10347 已知三中线求三角形面积

    已知中线长度,求三角形面积。

    = =

    我还推导出来各边边长了,结果一直WA,可能是判断面积不合法有点问题。

    后来发现这个有公式。。。神呐。。。

    这个是我推导的

    公式 已知中线x y z 求边长 a b c 

    double a = 2.0/3.0*sqrt(2*x*x + 2*z*z - y*y);

    double b = 2.0/3.0*sqrt(2*y*y + 2*z*z - x*x);

    double c = 2.0/3.0*sqrt(2*x*x + 2*y*y - z*z);

    公式推导

    http://jwilson.coe.uga.edu/emt725/Medians.Triangle/Area.Medians.Tri.html

    View Code
     1 #include <queue>
     2 #include <stack>
     3 #include <math.h>
     4 #include <stdio.h>
     5 #include <stdlib.h>
     6 #include <iostream>
     7 #include <limits.h>
     8 #include <string.h>
     9 #include <string>
    10 #include <algorithm>
    11 
    12 using namespace std;
    13 
    14 double area_triangle(double a,double b,double c)
    15 {
    16     double p = (a+b+c)/2.0;
    17     return sqrt(p*(p-a)*(p-b)*(p-c));
    18 }
    19 bool check(double a,double b,double c)
    20 {
    21     if( a >= b + c || a <= fabs(b-c) )
    22         return true;
    23     return false;
    24 }
    25 int main()
    26 {
    27     double x,y,z;
    28     
    29     while( ~scanf("%lf%lf%lf",&x,&y,&z) )
    30     {
    31         if( check(x,y,z) || check(y,x,z) || check(z,x,y) )
    32         {
    33             printf("-1.000\n");
    34             continue;
    35         }
    36         double area = 4.0/3*area_triangle(x,y,z);
    37         if( area <= 0 )
    38             printf("-1.000\n");
    39         else
    40             printf("%.3lf\n",area);
    41     }
    42 
    43 return 0;
    44 }

    转自:http://blog.csdn.net/zxy_snow/article/details/6579336

  • 相关阅读:
    左偏树
    论在Windows下远程连接Ubuntu
    ZOJ 3711 Give Me Your Hand
    SGU 495. Kids and Prizes
    POJ 2151 Check the difficulty of problems
    CodeForces 148D. Bag of mice
    HDU 3631 Shortest Path
    HDU 1869 六度分离
    HDU 2544 最短路
    HDU 3584 Cube
  • 原文地址:https://www.cnblogs.com/proverbs/p/2932806.html
Copyright © 2011-2022 走看看