题解 | #直角三角形#
直角三角形
https://www.nowcoder.com/practice/54ef7fa64c63442d87b9c836ef9c7701
#include <iostream>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <iomanip>
using namespace std;
float distance(int x1, int y1, int x2, int y2) {
return sqrt(pow((x2 - x1), 2) + pow((y2 - y1), 2));
}
int main() {
int m;
cin >> m;
while (m--) {
int x1, y1, x2, y2, x3, y3;
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
float d1 = distance(x1, y1, x2, y2);
float d2 = distance(x2, y2, x3, y3);
float d3 = distance(x3, y3, x1, y1);
float d[] = {d1, d2, d3};
sort(d, d + 3);
if (abs(pow(d[0], 2) + pow(d[1], 2) - pow(d[2], 2)) < 1e-4) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
cout << fixed << setprecision(2) << accumulate(d, d + 3, 0.0) << endl;
}
return 0;
}