Files
python/TangDou/AoSaiYiBenTong/YBT1034.cpp

25 lines
832 B
C++
Raw Normal View History

2025-08-30 18:35:01 +08:00
#include <bits/stdc++.h>
using namespace std;
int main() {
//cin读入优化
std::ios::sync_with_stdio(false);
float x1, y1, x2, y2, x3, y3;
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
//求三条边的长度,然后再用海伦公式进行求解
double a, b, c;
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));
double p = (a + b + c) / 2;
//假设在平面内,有一个三角形,边长分别为a、b、c
//三角形的面积S可由以下公式求得:
//S=√[p(p-a)(p-b)(p-c)]
//而公式里的p为半周长:p=(a+b+c)/2
cout << fixed << setprecision(2) << sqrt(p * (p - a) * (p - b) * (p - c)) << endl;
return 0;
}