UVA 10522 - Height to Area(计算几何)

这题就海伦公式带进去就可以了。。

要注意的是,这题的样例,是输入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

UVA 10522 - Height to Area(计算几何)的相关文章

UVA 10522 Height to Area(知三角形三高求面积)

思路:海伦公式, AC代码: 1 #include<bits/stdc++.h> 2 using namespace std; 3 int main() 4 { 5 int n; 6 scanf("%d",&n); 7 double ha, hb, hc, a, b, c; 8 while(~scanf("%lf %lf %lf",&ha,&hb,&hc)) 9 { 10 a = 2.0 / ha; 11 b = 2.0

uva 10652 Board Wrapping (计算几何-凸包)

Problem B Board Wrapping Input: standard input Output: standard output Time Limit: 2 seconds The small sawmill in Mission, British Columbia, has developed a brand new way of packaging boards for drying. By fixating the boards in special moulds, the b

UVA 11178 Morley&#39;s Theorem 计算几何

计算几何: 最基本的计算几何,差积  旋转 Morley's Theorem Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu Submit Status Description Problem D Morley's Theorem Input: Standard Input Output: Standard Output Morley's theorem states that that the line

HDU 1798 Tell me the area (计算几何)

Tell me the area Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1801    Accepted Submission(s): 542 Problem Description There are two circles in the plane (shown in the below picture), there is

uva 11796 Dog Distance (计算几何-点和直线)

C Dog Distance Input Standard Input Output Standard Output Two dogs, Ranga and Banga, are running randomly following two different paths. They both run for T seconds with different speeds. Ranga runs with a constant speed of R m/s, whereas Banga runs

UVa 1641 ASCII Area (计算几何,水题)

题意:给定一个矩阵,里面有一个多边形,求多边形的面积. 析:因为是在格子里,并且这个多边形是很规则的,所以所有格子不是全属于多边形就是全不属于,或者一半,并且我们可以根据"/"和“\”的数目来知道,如果是奇数,那么就是属于, 偶数就是不属于. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #in

UVA - 11437 - Triangle Fun (计算几何~)

UVA - 11437 Triangle Fun Time Limit: 1000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu Submit Status Description Problem A Triangle Fun Input: Standard Input Output: Standard Output In the picture below you can see a triangle ABC. Point D, E

UVA - 11796 - Dog Distance (计算几何~)

不得不感叹,计算几何真是太美丽了!! AC代码: #include <cstdio> #include <cstring> #include <algorithm> #include <iostream> #include <cmath> using namespace std; struct Point { double x, y; Point(double x = 0, double y = 0) : x(x) , y(y) { } }; t

POJ 1654 Area 计算几何

#include<stdio.h> #include<string.h> #include<iostream> #include<math.h> using namespace std; int dx[10]={0,1,1,1,0,0,0,-1,-1,-1}; int dy[10]={0,-1,0,1,-1,0,1,-1,0,1}; char s[1000010]; __int64 area,x,y,px,py; int main() { int sum,t