LightOJ 1118 - Incredible Molecules (两圆面积交)

1118 - Incredible Molecules
Time Limit: 0.5 second(s) Memory Limit: 32 MB

In the biological lab, you were examining some of the molecules. You got some interesting behavior about some of the molecules. There are some circular molecules, when two of them collide, they overlap with each other, and it's hard to find that which one is over the other one.

Given two molecules as circles, you have to find the common area of the given molecules that is shaded in the picture.

 

Overlapping Molecules

Input

Input starts with an integer T (≤ 12), denoting the number of test cases.

Each case contains six integers x1, y1, r1 and x2, y2, r2. Where (x1, y1) is the center of the first molecule and r1 is the radius and (x2, y2) is the center of the second molecule and r2 is the radius. Both the radiuses are positive. No integer will contain more than 3 digits.

Output

For each test case, print the case number and the common area of the given molecules. Errors less than 10-6 will be ignored.

Sample Input

Output for Sample Input

3

0 0 10 15 0 10

-10 -10 5 0 -10 10

100 100 20 100 110 20

Case 1: 45.3311753978

Case 2: 35.07666099

Case 3: 860.84369

 

 

 

 

http://lightoj.com/volume_showproblem.php?problem=1118

 

很简单,作为模板了

 

 1 /* ***********************************************
 2 Author        :kuangbin
 3 Created Time  :2013-10-15 18:56:20
 4 File Name     :E:\2013ACM\专题强化训练\计算几何\LightOJ1118.cpp
 5 ************************************************ */
 6 
 7 #include <stdio.h>
 8 #include <string.h>
 9 #include <iostream>
10 #include <algorithm>
11 #include <vector>
12 #include <queue>
13 #include <set>
14 #include <map>
15 #include <string>
16 #include <math.h>
17 #include <stdlib.h>
18 #include <time.h>
19 using namespace std;
20 
21 const double eps = 1e-8;
22 const double PI = acos(-1.0);
23 struct Point
24 {
25     double x,y;
26     void input()
27     {
28         scanf("%lf%lf",&x,&y);
29     }
30 };
31 double dist(Point a,Point b)
32 {
33     return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
34 }
35 //两个圆的公共部分面积
36 double Area_of_overlap(Point c1,double r1,Point c2,double r2)
37 {
38     double d = dist(c1,c2);
39     if(r1 + r2 < d + eps)return 0;
40     if(d < fabs(r1 - r2) + eps)
41     {
42         double r = min(r1,r2);
43         return PI*r*r;
44     }
45     double x = (d*d + r1*r1 - r2*r2)/(2*d);
46     double t1 = acos(x / r1);
47     double t2 = acos((d - x)/r2);
48     return r1*r1*t1 + r2*r2*t2 - d*r1*sin(t1);
49 }
50 
51 int main()
52 {
53     //freopen("in.txt","r",stdin);
54     //freopen("out.txt","w",stdout);
55     Point c1,c2;
56     double r1,r2;
57     int T;
58     scanf("%d",&T);
59     int iCase = 0;
60     while(T--)
61     {
62         iCase ++;
63         c1.input();
64         scanf("%lf",&r1);
65         c2.input();
66         scanf("%lf",&r2);
67         printf("Case %d: %.6lf\n",iCase,Area_of_overlap(c1,r1,c2,r2));
68     }
69     return 0;
70 }

 

 

 

 

 

你可能感兴趣的:(DI)