博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu 5120 Intersection 两个圆的面积交
阅读量:5341 次
发布时间:2019-06-15

本文共 2907 字,大约阅读时间需要 9 分钟。

Intersection

Time Limit: 4000/4000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others)

Problem 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 you may know.
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.
 

 

Input
The first line contains only one integer T (T ≤ 10
5), which indicates the number of test cases. For each test case, the first line contains two integers r, R (0 ≤ r < R ≤ 10).
Each of the following two lines contains two integers x
i, y
i (0 ≤ x
i, y
i ≤ 20) indicating the coordinates of the center of each ring.
 

 

Output
For each test case, output a single line “Case #x: y”, where x is the case number (starting from 1) and y is the area of intersection rounded to 6 decimal places.
 

 

Sample Input
2 2 3 0 0 0 0 2 3 0 0 5 0
 

 

Sample Output
Case #1: 15.707963 Case #2: 2.250778
 

 

Source

题意:求两个圆环的面积交;

思路:圆环的面积交=大圆面积交-2*大小圆面积交+小圆面积交;

#include
using namespace std;#define LL long long#define fi first#define se second#define mkp make_pair#define eps 1e-8const double pi=acos(-1);const int N=2e5+60,M=1e6+10,inf=1e9+10;const LL INF=1e18+10,mod=19260817;int sgn(double x){ if(fabs(x) < eps)return 0; if(x < 0)return -1; else return 1;}struct Point{ double x,y; Point() {} Point(double _x,double _y) { x = _x; y = _y; } Point operator -(const Point &b)const { return Point(x - b.x,y - b.y); } //叉积 double operator ^(const Point &b)const { return x*b.y - y*b.x; }//点积 double operator *(const Point &b)const { return x*b.x + y*b.y; }//绕原点旋转角度B(弧度值),后x,y的变化 void transXY(double B) { double tx = x,ty = y; x= tx*cos(B) - ty*sin(B); y= tx*sin(B) + ty*cos(B); }};double AREA(Point a, double r1, Point b, double r2){ double d = sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y)); if (d >= r1+r2) return 0; if (r1>r2) { double tmp = r1; r1 = r2; r2 = tmp; } if(r2 - r1 >= d) return pi*r1*r1; double ang1=acos((r1*r1+d*d-r2*r2)/(2*r1*d)); double ang2=acos((r2*r2+d*d-r1*r1)/(2*r2*d)); return ang1*r1*r1 + ang2*r2*r2 - r1*d*sin(ang1);}int main(){ int T,cas=1; scanf("%d",&T); while(T--) { double r1,r2; Point a,b; scanf("%lf%lf%lf%lf%lf%lf",&r1,&r2,&a.x,&a.y,&b.x,&b.y); printf("Case #%d: %.6f\n",cas++,AREA(a,r2,b,r2)-AREA(a,r1,b,r2)-AREA(a,r2,b,r1)+AREA(a,r1,b,r1)); } return 0;}

 

转载于:https://www.cnblogs.com/jhz033/p/7449482.html

你可能感兴趣的文章
Road Map
查看>>
正则替换中的一个Bug
查看>>
HI3531uboot开机画面 分类: arm-linux-Ubunt...
查看>>
制作U盘启动CDLinux 分类: 生活百科 ...
查看>>
leetcode——Best Time to Buy and Sell Stock
查看>>
Android LinearLayout 的几个属性
查看>>
strcpy函数里的小九九
查看>>
搭建ssm过程中遇到的问题集
查看>>
OpenLayers绘制图形
查看>>
tp5集合h5 wap和公众号支付
查看>>
Flutter学习笔记(一)
查看>>
iOS10 国行iPhone联网权限问题处理
查看>>
洛谷 P1991 无线通讯网
查看>>
[HIHO1184]连通性二·边的双连通分量(双连通分量)
查看>>
Codeforces Round #178 (Div. 2) B. Shaass and Bookshelf 【动态规划】0-1背包
查看>>
SparkStreaming 源码分析
查看>>
【算法】—— 随机音乐的播放算法
查看>>
mysql asyn 示例
查看>>
DataGrid 点击 获取 行 ID
查看>>
git 使用
查看>>