S5來襲4/11旗艦上市直擊★美車模手癢不小心...這畫面也太叫人垂涎欲滴!色令人昏 喜會女網友悲...
2012-05-05 21:41:57 人氣(270) | 回應(0) | 推薦(0) | 收藏(0) 上一篇 | 下一篇

[UVA][Math] 10991 - Region

0
收藏
0
推薦

Problem B
Region
Input: Standard Input

Output: Standard Output

 

From above figure, it is clear that C1, C2 and C3 circles are touching each other.

 

Consider,

 

            C1 circle have R1 radius.

            C2 circle have R2 radius.

            C3 circle have R3 radius.

 

Write a program that will calculate the area of shaded region G

 

Input

The first line will contain an integer k (1 ≤ k ≤ 1000) which is the number of cases to solve. Each of the following k Lines will contain three floating point number R1 (1 ≤ R1 ≤ 1000), R2 (1 ≤ R2 ≤ 1000) and R3 (1 ≤ R3 ≤ 1000).

 

Output

For each line of input, generate one line of output containing the area of G rounded to six decimal digits after the decimal point. Floating-point errors will be ignored by special judge program.

 

Sample Input                               Output for Sample Input

2

5.70 1.00 7.89

478.61 759.84 28.36

 

1.224323

2361.005761

 



犯下了大錯, asin 的範圍是在 pi/2 ~ -pi/2
因此會有問題, 所以要用 acos, 用餘弦定理

#include <stdio.h>
#include <math.h>
int main() {
    double r1, r2, r3, theta;
    double area, a, b, c, s, ans;
    int t;
    scanf("%d", &t);
    while(t--) {
        scanf("%lf %lf %lf", &r1, &r2, &r3);
        a = r1+r2, b = r2+r3, c = r3+r1;
        s = (a+b+c)/2;
        area = sqrt(s*(s-a)*(s-b)*(s-c));
        ans = area;
        theta = acos((a*a+c*c-b*b)/2/a/c);
        ans -= r1*r1*theta/2;
        theta = acos((a*a+b*b-c*c)/2/a/b);
        ans -= r2*r2*theta/2;
        theta = acos((b*b+c*c-a*a)/2/b/c);
        ans -= r3*r3*theta/2;
        printf("%lf\n", ans);
    }
    return 0;
}

 

10991Region
台長:Morris
人氣(270) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA] 11650 - Mirror Clock
此分類上一篇:[UVA][Math] 474 - Heads / Tails Probability

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

(有*為必填)
詳全文