24h購物| | PChome| 登入
2012-05-05 21:41:57| 人氣722| 回應0 | 上一篇 | 下一篇

[UVA][Math] 10991 - Region

推薦 0 收藏 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;
}

 

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

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文