2012-05-05 21:41:57Morris

[UVA][Math] 10991 - Region

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;
}