文章

121

粉丝

68

获赞

94

访问

20.4k

头像
求三角形面积 题解:亲测答案一致,不知道为什么过不去验证
P5111
发布于2025年2月5日 14:41
阅读数 151

#include <bits/stdc++.h>
using namespace std;

struct triEdge{
    int x1,y1;
    int x2,y2;
    double length;
    triEdge():x1(0),y1(0),x2(0),y2(0),length(0){}
    triEdge(int x1,int y1,int x2,int y2){
        this->x1 = x1;
        this->y1 = y1;
        this->x2 = x2;
        this->y2 = y2;
        this->length = sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
    }
};

int main(){
    int a,b,c,d,e,f;
    while(cin>>a>>b>>c>>d>>e>>f){
        triEdge te1 = triEdge(a,b,c,d);
        triEdge te2 = triEdge(a,b,e,f);
        triEdge te3 = triEdge(c,d,e,f);
        double p = (te1.length + te2.length + te3.length) / 2;
        double s = sqrt(p * (p - te1.length) * (p - te2.length) * (p - te3.length));
        printf("%.2lf\n", s);
    }
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发