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 below.

Matt just designed a new logo consisting of two rings with the same size in the 2-D plane. For his interests, Matt would like to know the area of the intersection of these two rings.

题意:求两个相同大小的圆环的面积交。

解法:几何,圆的面积交模板。画一个图应该就能发现公式:圆环面积交=大圆大圆面积交-2×大圆小圆面积交+小圆小圆面积交。

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<cstdlib>
 5 #include<cmath>
 6 #include<algorithm>
 7 #define inf 0x7fffffff
 8 #define exp 1e-10
 9 #define PI 3.141592654
10 using namespace std;
11 typedef long long ll;
12 struct Point
13 {
14     double x,y;
15     Point (double x=0,double y=0):x(x),y(y){}
16 };
17 double dist(Point a,Point b)
18 {
19     double x=(a.x-b.x)*(a.x-b.x);
20     double y=(a.y-b.y)*(a.y-b.y);
21     return sqrt(x+y);
22 }
23 double Area_of_overlap(Point c1,double r1,Point c2,double r2)
24 {
25     double d=dist(c1,c2);
26     if (r1+r2<d+exp) return 0;
27     if (d<fabs(r1-r2)+exp)
28     {
29         double r=min(r1,r2);
30         return PI*r*r;
31     }
32     double x=(d*d+r1*r1-r2*r2)/(2*d);
33     double t1=acos(x/r1);
34     double t2=acos((d-x)/r2);
35     return r1*r1*t1+r2*r2*t2-d*r1*sin(t1);
36 }
37 int main()
38 {
39     int t,ncase=1;
40     double r,R;
41     Point a,b;
42     scanf("%d",&t);
43     while (t--)
44     {
45         scanf("%lf%lf",&r,&R);
46         scanf("%lf%lf%lf%lf",&a.x,&a.y,&b.x,&b.y);
47         double bb_area=Area_of_overlap(a,R,b,R);
48         double bs_area=Area_of_overlap(a,R,b,r);
49         double ss_area=Area_of_overlap(a,r,b,r);
50         printf("Case #%d: %.6lf\n",ncase++,bb_area-2.0*bs_area+ss_area);
51     }
52     return 0;
53 }
时间: 2024-10-21 15:28:16

hdu 5120 Intersection的相关文章

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(2014北京赛区现场赛I题 计算几何)

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

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(圆的面积交)

题目大意:给你两个圆环,让你求出来圆环的面积交,需要用到圆的面积交,然后容斥一下,就可以得到圆环的面积交.画一下图就会很清晰. 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(几何模板题)

题意:给定两个圆环,求两个圆环相交的面积. 思路:由于圆心和半径不一样,分了好多种情况,后来发现只要把两个圆相交的函数写好之后就不需要那么复杂了.两个圆相交的面积的模板如下: 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)

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

HDOJ 5120 Intersection 两圆面积交

两圆面积交.... Intersection Time Limit: 4000/4000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others) Total Submission(s): 101    Accepted Submission(s): 38 Problem Description Matt is a big fan of logo design. Recently he falls in love with l

HDU 5120 A Curious Matt(2014北京赛区现场赛A题 简单模拟)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5112 解题报告:扫一遍 1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 #include<algorithm> 5 #include<cmath> 6 using namespace std; 7 const int maxn = 1e6+5; 8 9 struct node

hdu 5120 (求两圆相交的面积

题意:告诉你两个圆环,求圆环相交的面积. /* gyt Live up to every day */ #include<cstdio> #include<cmath> #include<iostream> #include<algorithm> #include<vector> #include<stack> #include<cstring> #include<queue> #include<set&