Hrbust 2001 三角形面積

這裏寫圖片描述

#include<stdio.h>
#include<math.h>


int main(void)
{
    int T;
    double x1, y1, x2, y2, x3, y3;
    double a, b, c, p, s;
    scanf("%d", &T);
    while(T--){
        scanf("%lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3);
        a = sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
        b = sqrt((x1-x3)*(x1-x3)+(y1-y3)*(y1-y3));
        c = sqrt((x3-x2)*(x3-x2)+(y3-y2)*(y3-y2));
        if(a+b <= c || a+c <= b || b+c <= a){
            puts("fail");
            continue;
        }
        p = (a + b + c) / 2;
        s = sqrt(p * (p - a) * (p - b) * (p - c));
        printf("%.2lf\n", s);
    }
    return 0;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章