Files
python/TangDou/AoSaiYiBenTong/YBT1034.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

25 lines
832 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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;
}