A - A
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu
Submit Status Practice LightOJ 1331
Description
Agent J is preparing to steal an antique diamond piece from a museum. As it is fully guarded and they are guarding it using high technologies, it‘s not easy to steal the piece. There are three circular laser scanners in the museum which are the main headache for Agent J. The scanners are centered in a certain position, and they keep rotating maintaining a certain radius. And they are placed such that their coverage areas touch each other as shown in the picture below:
Here R1, R2 and R3 are the radii of the coverage areas of the three laser scanners. The diamond is placed in the place blue shaded region as in the picture. Now your task is to find the area of this region for Agent J, as he needs to know where he should land to steal the diamond.
Input
Input starts with an integer T (≤ 1000), denoting the number of test cases.
Each case starts with a line containing three real numbers denoting R1, R2 and R3 (0 < R1, R2, R3 ≤ 100). And no number contains more than two digits after the decimal point.
Output
For each case, print the case number and the area of the place where the diamond piece is located. Error less than 10-6 will be ignored.
Sample Input
3
1.0 1.0 1.0
2 2 2
3 3 3
Sample Output
Case 1: 0.16125448
Case 2: 0.645017923
Case 3: 1.4512903270
题解:
求三个圆围成的区域面积,注意要用acos,asin会出错,因为sin150 = 1/2, sin30 = 1/2;这样asin就出错了。。
代码:
#include<iostream> #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> using namespace std; template<typename T, typename T1> T getcos(T1 a, T b, T c){ return (b*b + c*c - a*a) / (2*b*c); } template<typename T> T Angarea(T a, T b, T c){ return 0.5 * b * c * sin(a); } template<typename T> T cirarea(T a, T r){ return 0.5 * a * r * r; } int main(){ int T; double r1, r2, r3; int kase = 0; scanf("%d", &T); while(T--){ scanf("%lf%lf%lf", &r1, &r2, &r3); double cosa = getcos(r2 + r3, r1 + r2, r1 + r3); double cosb = getcos(r1 + r2, r2 + r3, r1 + r3); double cosc = getcos(r1 + r3, r1 + r2, r2 + r3); double a = acos(cosa); double b = acos(cosb); double c = acos(cosc); double ans = Angarea(a, r1 + r2, r1 + r3) - cirarea(a, r1) - cirarea(b, r3) - cirarea(c, r2); printf("Case %d: %lf\n", ++kase, ans); } return 0; }