投資錢景>買台積電就對了三星平板★瘋殺5290起正妹的東京自助旅行療傷止痛,王郁琦先下台!
2013-07-07 16:08:27 人氣(90) | 回應(0) | 推薦(0) | 收藏(0) 上一篇 | 下一篇

[UVA][math] 10522 - Height to Area

0
收藏
0
推薦

THE SAMS' CONTEST

Problem 3

Height to Area 

Problem

    It's an easy geometry problem. For any triangle ABC we know that the height from A to the line BC (or it's extension) is Ha, from B to the line AC (or it's extension) is Hb and from C to the line AB (or it's extension) is Hc. Now you are given these three values and you have to figure out the area of the ABC .

                              

Input

    At first the input will be an integer n. Which denotes the number of invalid inputs after which the input will terminate. Then there will be three real numbers Ha, Hb and Hc per line.

Output

    For each input block there should be one output line. For valid inputs the line contains the area of the ABC up to 3 decimal places after the decimal point and for invalid inputs there will be a line "These are invalid inputs!". After n invalid input sets the program will terminate.

Sample Input

1
31.573 22.352 63.448
46.300 50.868 86.683
22.005 24.725 22.914
5.710 25.635 32.805
 

Sample Output

1517.456
2219.941
311.804
These are invalid inputs!


Enamul Haque


Triangle is a very fine geometrical shape,

 you can't say this is bad;

But if you familiar with "Triangle Love",

                      you must know that will make you sad.

--- Moni.


設點 A, B, C 分別對應的邊為 a, b, c
則由於面積相同 

A(area) = 0.5a*Ha = 0.5b*Hb = 0.5c*Hc

接著利用海龍公式
Heron's formula
s = (a+b+c)/2
A = sqrt((s)*(s-a)*(s-b)*(s-c))


將 s 中的 a, b, c 替換,
最後得到

A = A*A * sqrt((1/Ha+1/Hb+1/Hc)*(1/Hb+1/Hc-1/Ha)*(1/Ha+1/Hc-1/Hb)*(1/Hb+1/Ha-1/Hc))
A = 1/sqrt((1/Ha+1/Hb+1/Hc)*(1/Hb+1/Hc-1/Ha)*(1/Ha+1/Hc-1/Hb)*(1/Hb+1/Ha-1/Hc));

#include <stdio.h>
#include <math.h>
int main() {
    int cases = 0;
    scanf("%d", &cases);
    while(cases) {
        double Ha, Hb, Hc;
        scanf("%lf %lf %lf", &Ha, &Hb, &Hc);
        double val;
        val = (1/Ha+1/Hb+1/Hc)*(1/Hb+1/Hc-1/Ha)*(1/Ha+1/Hc-1/Hb)*(1/Hb+1/Ha-1/Hc);
#define eps 1e-8
        if(val < eps || fabs(Ha) < eps || fabs(Hb) < eps || fabs(Hc) < eps) {
            puts("These are invalid inputs!");
            cases--;
            continue;
        }
        printf("%.3lf\n", 1/sqrt(val));
    }
    return 0;
}
/*
A(area) = 0.5a*Ha = 0.5b*Hb = 0.5c*Hc
Heron's formula
s = (a+b+c)/2
A = sqrt((s)*(s-a)*(s-b)*(s-c))
A = A*A * sqrt((1/Ha+1/Hb+1/Hc)*(1/Hb+1/Hc-1/Ha)*(1/Ha+1/Hc-1/Hb)*(1/Hb+1/Ha-1/Hc))
A = 1/sqrt((1/Ha+1/Hb+1/Hc)*(1/Hb+1/Hc-1/Ha)*(1/Ha+1/Hc-1/Hb)*(1/Hb+1/Ha-1/Hc));
*/

10522Height to Areamath海龍
台長:Morris
人氣(90) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA] 10528 - Major Scales
此分類上一篇:[UVA][牛頓法] 10428 - The Roots

我要回應
是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入以下數字 (ex:123)

(有*為必填)
詳全文