codeforce--600D - Area of Two Circles' Intersection

题意:求相交圆的面积。借鉴大神代码,精度超高。

 1 #include <fstream>
 2 #include <iostream>
 3 #include <string>
 4 #include <complex>
 5 #include <math.h>
 6 #include <set>
 7 #include <vector>
 8 #include <map>
 9 #include <queue>
10 #include <stdio.h>
11 #include <stack>
12 #include <algorithm>
13 #include <list>
14 #include <ctime>
15 #include <memory.h>
16 #include <ctime>
17 #include <assert.h>
18 
19 #define y1 aasdfasdfasdf
20 
21 #define eps 1e-16
22 #define M_PI 3.141592653589793
23 const int N = 200005;
24 using namespace std;
25 
26 long double x1,y1,x2,y2,r1,r2;
27 
28 long double gd(long double x1,long double y1,long double x2,long double y2)
29 {
30     return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
31 }
32 
33 long double solve_cos(long double a,long double b,long double c)
34 {
35     return acos((a*a+b*b-c*c)/(2*a*b));
36 }
37 
38 long double cut(long double ang,long double r)
39 {
40     long double s1,s2;
41     s1=ang*r*r/2;
42     s2=sin(ang)*r*r/2;
43     return s1-s2;
44 }
45 
46 long double solve()
47 {
48     if (r1<r2)
49     {
50         swap(x1,x2);
51         swap(y1,y2);
52         swap(r1,r2);
53     }
54     long double cd=gd(x1,y1,x2,y2);
55     if (cd+r2<=r1+eps)
56         return r2*r2*M_PI;
57     if (cd>=r1+r2-eps)
58         return 0;
59     long double ang1=solve_cos(cd,r1,r2);
60     long double ang2=solve_cos(cd,r2,r1);
61     return cut(ang1*2,r1)+cut(ang2*2,r2);
62 }
63 
64 int main()
65 {
66     cin>>x1>>y1>>r1;
67     cin>>x2>>y2>>r2;
68     cout.precision(12);
69     cout<<fixed<<solve()<<endl;
70     return 0;
71 }
View Code

 

posted @ 2015-11-28 16:06  yyblues  阅读(280)  评论(0编辑  收藏  举报