NYOJ67三角形面积

题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=67


一个海伦公式,不解释。


#include <cstdio>
#include <cmath>

double dis(double x1,double y1,double x2,double y2)

{
    return sqrt(pow(x1 - x2,2) + pow(y1 - y2,2));
}

int main()

{
    double x1,y1,x2,y2,x3,y3;
    while(~scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3),x1+y1+x2+y2+x3+y3)
    {
        double a = dis(x1,y1,x2,y2);
        double b = dis(x1,y1,x3,y3);
        double c = dis(x2,y2,x3,y3);
        double p = 0.5 * (a + b + c);
        double ans = sqrt(p * (p - a) * (p - b) * (p - c));
        printf("%.1f\n",ans);
    }
    return 0;
}

你可能感兴趣的:(ACM,面积,海伦公式,任意三角形)