HDU5120

这题求的是圆环相交的面积,画图可知  圆环相交面积=大交大-2×大交小+小交小

这题需要用到圆的相交面积公式

题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=93642#problem/I

 

AC代码:

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <math.h>
 4 #include <algorithm>
 5 #define exp 1e-10
 6 #define PI 3.141592654
 7 using namespace std;
 8 typedef long long LL;
 9 struct point
10 {
11     double x,y;
12     point(double x=0,double y=0):x(x),y(y){}
13 }a,b;
14 
15 double dist(point a,point b)
16 {
17     double x=(a.x-b.x)*(a.x-b.x);
18     double y=(a.y-b.y)*(a.y-b.y);
19     return sqrt(x+y);
20 }
21 
22 double overlap(point c1,double r1,point c2,double r2)
23 {
24     double d=dist(c1,c2);
25     if(r1+r2<d+exp)
26     {
27         return 0;
28     }
29     if(d<fabs(r1-r2)+exp)
30     {
31         double r=min(r1,r2);
32         return PI*r*r;
33     }
34     double x=(d*d+r1*r1-r2*r2)/(2*d);
35     double t1=acos(x/r1);
36     double t2=acos((d-x)/r2);
37     return r1*r1*t1+r2*r2*t2-d*r1*sin(t1);
38 }
39 
40 int main()
41 {
42     int T,f;
43     f=0;
44     double r,R;
45     scanf("%d",&T);
46     while(T--)
47     {
48         f++;
49         scanf("%lf%lf",&r,&R);
50         scanf("%lf%lf%lf%lf",&a.x,&a.y,&b.x,&b.y);
51         double big=overlap(a,R,b,R);
52         double bigsmall=overlap(a,R,b,r);
53         double small=overlap(a,r,b,r);
54         printf("Case #%d: %.6lf\n",f,big-2*bigsmall+small);
55     }
56     return 0;
57 }
View Code

 

转载于:https://www.cnblogs.com/qioalu/p/4858461.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值