1 条题解
-
0
#include <iostream> #include <cmath> #include <string> #include <algorithm> using namespace std; const double EPS = 1e-6; // 计算两点距离的平方 double dist2(double x1, double y1, double x2, double y2) { return (x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2); } // 判断是否为三角形(任意两边之和大于第三边) bool isTriangle(double a, double b, double c) { return (a + b > c + EPS) && (a + c > b + EPS) && (b + c > a + EPS); } int main() { double x1, y1, x2, y2, x3, y3; while (cin >> x1) { if (x1 == -1) break; cin >> y1 >> x2 >> y2 >> x3 >> y3; double a2 = dist2(x1, y1, x2, y2); // 边长平方 double b2 = dist2(x2, y2, x3, y3); double c2 = dist2(x3, y3, x1, y1); double a = sqrt(a2), b = sqrt(b2), c = sqrt(c2); // 按边排序(a <= b <= c) double sides[3] = {a, b, c}; sort(sides, sides + 3); a = sides[0]; b = sides[1]; c = sides[2]; // 三角形有效性检查 if (!isTriangle(a, b, c)) { cout << "Not a Triangle" << endl; continue; } // 边分类 string lengthType; if (fabs(a - b) < 0.01 && fabs(b - c) < 0.01) lengthType = "Equilateral"; else if (fabs(a - b) < 0.01 || fabs(b - c) < 0.01 || fabs(a - c) < 0.01) lengthType = "Isosceles"; else lengthType = "Scalene"; // 角分类(使用余弦定理或边长平方判别) string angleType; double a2_ = a * a, b2_ = b * b, c2_ = c * c; if (fabs(c2_ - (a2_ + b2_)) < 0.01) angleType = "Right"; else if (c2_ < a2_ + b2_ - 0.01) angleType = "Acute"; else angleType = "Obtuse"; cout << lengthType << " " << angleType << endl; } cout << "End of Output" << endl; return 0; }
- 1
信息
- ID
- 587
- 时间
- 1000ms
- 内存
- 10MiB
- 难度
- 8
- 标签
- 递交数
- 5
- 已通过
- 0
- 上传者