这题就海伦公式带进去就可以了。。
要注意的是,这题的样例,是输入n次错误的输入才停止。。,输入的可能是负数。
代码:
#include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; const double eps = 1e-8; int t; double Ha, Hb, Hc; int dcmp(double x) { if (fabs(x) < eps) return 0; else return x < 0 ? -1 : 1; } int main() { scanf("%d", &t); while (t) { scanf("%lf%lf%lf", &Ha, &Hb, &Hc); double a = 2 / Ha, b = 2 / Hb, c = 2 / Hc; double p = (a + b + c) / 2; double tmp = p * (p - a) * (p - b) * (p - c); if (dcmp(Ha) <= 0 || dcmp(Hb) <= 0 || dcmp(Hc) <= 0 || dcmp(tmp) <= 0) { t--; printf("These are invalid inputs!\n"); continue; } double ans = 1.0 / sqrt(tmp); printf("%.3f\n", ans); } return 0; }
时间: 2024-10-09 18:26:54