HDU 5120 Intersection (求圆环相交面积)

题意:给定圆环的内径r和外径R,以及2个相同圆环的圆心,求两个圆环的相交面积。

思路

S = A大B大 - A大B小 - A小B大 + A小B小。(A表示A环,大表示大圆,B同)

 1 #include <iostream>
 2 #include <queue>
 3 #include <stack>
 4 #include <cstdio>
 5 #include <vector>
 6 #include <map>
 7 #include <set>
 8 #include <bitset>
 9 #include <algorithm>
10 #include <cmath>
11 #include <cstring>
12 #include <cstdlib>
13 #include <string>
14 #include <sstream>
15 #include <time.h>
16 #define x first
17 #define y second
18 #define pb push_back
19 #define mp make_pair
20 #define lson l,m,rt*2
21 #define rson m+1,r,rt*2+1
22 #define mt(A,B) memset(A,B,sizeof(A))
23 using namespace std;
24 typedef long long LL;
25 typedef unsigned long long ull;
26 const double PI = acos(-1);
27 const int N=1e6+10;
28 const LL mod=1e9+7;
29 const int inf = 0x3f3f3f3f;
30 const LL INF=0x3f3f3f3f3f3f3f3fLL;
31 const double eps=1e-8;
32 struct point
33 {
34     double x,y;
35     point(){}
36     point(double _x,double _y)
37     {
38         x=_x;
39         y=_y;
40     }
41 };
42 double dis(point a,point b)
43 {
44     return sqrt((a.x-b.x)*(a.x-b.x)+(b.y-a.y)*(b.y-a.y));
45 }
46 double cal(point c1,double r1,point c2,double r2)
47 {
48     double d=dis(c1,c2);
49     if(r1+r2<d+eps)return 0;
50     if(d<fabs(r1-r2)+eps)
51     {
52         double r=min(r1,r2);
53         return PI*r*r;
54     }
55     double x=(d*d+r1*r1-r2*r2)/(2*d);
56     double t1=acos(x/r1);
57     double t2=acos((d-x)/r2);
58     return r1*r1*t1+r2*r2*t2-d*r1*sin(t1);
59 }
60 int main()
61 {
62 #ifdef Local
63     freopen("data.h","r",stdin);
64 #endif
65     //ios::sync_with_stdio(false);
66     //cin.tie(0);
67     int cas=1,T,n,m;
68     scanf("%d",&T);
69     while(T--)
70     {
71         double r,R,ans;
72         struct point p,q;
73         cin>>r>>R;
74         cin>>p.x>>p.y;
75         cin>>q.x>>q.y;
76         if(dis(p,q)>=2*R)ans=0;
77         else
78         {
79             if(dis(p,q)>=2*r)
80             {
81                 ans=cal(p,R,q,R)-cal(p,r,q,R)-cal(q,r,p,R);
82             }
83             else
84             {
85                 ans=cal(p,R,q,R)-cal(p,r,q,R)-cal(q,r,p,R)+cal(q,r,p,r);
86             }
87         }
88         printf("Case #%d: %lf\n",cas++,ans);
89     }
90 #ifdef Local
91     cerr << "time: " << (LL) clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
92 #endif
93    return 0;
94 }

时间: 2024-12-21 06:51:16

HDU 5120 Intersection (求圆环相交面积)的相关文章

HDU 5120 Intersection(2014北京赛区现场赛I题 计算几何)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5120 解题报告:给你两个完全相同的圆环,要你求这两个圆环相交的部分面积是多少? 题意看了好久没懂.圆环由一个大圆里面套一个小圆,中间部分就是圆环,两圆环相交面积 = 大圆相交的面积 - 2*大圆与小圆相交的面积 + 小圆与小圆相交的面积. 也就是说,这题就可以化为求两个圆的相交的面积了.可以利用两个圆的方程,求出圆的交点所在的直线,然后求出圆心到这条直线的距离,就可以求出两个圆对应的扇形的圆心角是多

hdu 5120 Intersection 圆环面积交

Intersection Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5120 Description Matt is a big fan of logo design. Recently he falls in love with logo made up by rings. The following figures are some famous examples

HDU 5120 Intersection(圆的面积交)

题目大意:给你两个圆环,让你求出来圆环的面积交,需要用到圆的面积交,然后容斥一下,就可以得到圆环的面积交.画一下图就会很清晰. Intersection Time Limit: 4000/4000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others) Total Submission(s): 526    Accepted Submission(s): 226 Problem Description Matt is a b

hdu 5120 Intersection

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5120 A ring is a 2-D figure bounded by two circles sharing the common center. The radius for these circles are denoted by r and R (r < R). For more details, refer to the gray part in the illustration bel

hdu 5120 - Intersection(解题报告)

Intersection Time Limit: 4000/4000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others) Total Submission(s): 1036    Accepted Submission(s): 407 Problem Description Matt is a big fan of logo design. Recently he falls in love with logo made

HDU 5120 Intersection(几何模板题)

题意:给定两个圆环,求两个圆环相交的面积. 思路:由于圆心和半径不一样,分了好多种情况,后来发现只要把两个圆相交的函数写好之后就不需要那么复杂了.两个圆相交的面积的模板如下: double area_of_overlap(point c1, double r1, point c2, double r2) { double d = dist(c1, c2); if (sgn(d - r1 - r2) >= 0) return 0; if (sgn(fabs(r1 - r2) - d) >= 0)

hdu5012 圆环相交面积

题中给了 两个同心圆, 一个大圆一个小圆,然后再给了一个大圆一个小圆也是同心圆,求这两个圆环相交的面积,用两个大圆面积减去两倍大小圆面积交加上两个小圆面积交,就ok了 这里算是坑明白了 使用acos的时候要保证不能让大于1或者小于-1的数进来,因此加一个判断,在现场的时候就是这里被坑死了 #include <iostream> #include <cstdio> #include <algorithm> #include <cmath> #include &

hdu 1542(线段树+扫描线 求矩形相交面积)

Atlantis Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 12059    Accepted Submission(s): 5083 Problem Description There are several ancient Greek texts that contain descriptions of the fabled i

HDU 2056 Rectangles(计算相交面积)

Rectangles Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 20183    Accepted Submission(s): 6537 Problem Description Given two rectangles and the coordinates of two points on the diagonals of e