文章

94

粉丝

0

获赞

572

访问

17.7k

头像
求三角形的面积 题解:c++,海伦公式,看着顺眼
P1125 兰州大学/西北工业大学机试题
发布于2026年1月20日 15:08
阅读数 278

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

int main()
{
    double x1,y1,x2,y2,x3,y3;
    while(cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3){
        double a = sqrt(pow((x1 - x2),2) + pow((y1-y2),2));
        double b = sqrt(pow((x1 - x3),2) + pow((y1-y3),2));
        double c = sqrt(pow((x3 - x2),2) + pow((y3-y2),2));
        double p = (a + b + c) / 2.0;
        double result = sqrt(p * (p - a) * (p - b) * (p - c));
        printf("%.2f\n",result);
    }
    return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发