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

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

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 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 ≤ 105), 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 xi, yi (0 ≤ xi, yi ≤ 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

HINT

 

题意

给你两个一样的圆环,问你这两个圆环相交的面积是多少

题解:

容斥定理就好了,剩下的都是套版

面积=大交大-大交小+小交小

代码:

//qscqesze#pragma comment(linker, "/STACK:1024000000,1024000000")#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
typedef long long ll;using namespace std;//freopen("D.in","r",stdin);//freopen("D.out","w",stdout);#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)#define maxn 1000006#define mod 1001#define eps 1e-9#define PI acos(-1)const double EP = 1E-10 ;int Num;//const int inf=0x7fffffff;const ll inf=999999999;inline ll read(){ ll x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){ if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f;}//*************************************************************************************struct Circle{ double x,y; double r;};double calArea(Circle c1, Circle c2){ double d; double s,s1,s2,s3,angle1,angle2,temp; d=sqrt((c1.x-c2.x)*(c1.x-c2.x)+(c1.y-c2.y)*(c1.y-c2.y)); if(d>=(c1.r+c2.r))//两圆相离 return 0; if((c1.r-c2.r)>=d)//两圆内含,c1大 return acos(-1.0)*c2.r*c2.r; if((c2.r-c1.r)>=d)//两圆内含,c2大 return acos(-1.0)*c1.r*c1.r; angle1=acos((c1.r*c1.r+d*d-c2.r*c2.r)/(2*c1.r*d)); angle2=acos((c2.r*c2.r+d*d-c1.r*c1.r)/(2*c2.r*d)); s1=angle1*c1.r*c1.r;s2=angle2*c2.r*c2.r; s3=c1.r*d*sin(angle1); s=s1+s2-s3; return s;}int main(){ int t; scanf("%d",&t); for(int cas = 1;cas <= t;cas++) { Circle a1,a2,b1,b2; double R,r; scanf("%lf%lf",&a1.r,&a2.r); b1.r=a1.r; b2.r=a2.r; scanf("%lf%lf",&a1.x,&a1.y); scanf("%lf%lf",&b1.x,&b1.y); a2.x=a1.x; a2.y=a1.y; b2.x=b1.x; b2.y=b1.y; double ans = 0; ans += calArea(a1,b1); ans -= calArea(a1,b2); ans -= calArea(b1,a2); ans += calArea(a2,b2); printf("Case #%d: %.6lf\n",cas,ans); }}

 

转载地址:http://pqrxo.baihongyu.com/

你可能感兴趣的文章
Egret Engine(白鹭引擎)介绍及windows下安装
查看>>
一个小巧的C++Log输出到文件类 (转)
查看>>
Javascript动态操作CSS总结
查看>>
ZeroMQ接口函数之 :zmq_msg_init_size - 使用一个指定的空间大小初始化ZMQ消息对象...
查看>>
Linux 配置网络
查看>>
Effective JavaScript Item 21 使用apply方法调用函数以传入可变參数列表
查看>>
ViewPager中Fragment无法显示的问题
查看>>
FarBox--另类有趣的网站服务【转】
查看>>
可显示Android设备选择列表,并进入指定Android设备Console的Shell脚本
查看>>
HDU 2831 (贪心)
查看>>
遍历js的obj中所有属性得key
查看>>
lua demo
查看>>
iOS开发-UITapGestureRecognizer手势
查看>>
在QTreeWidget中删除QTreeWidgetItem
查看>>
网页引导:jQuery插件实现的页面功能介绍引导页效果
查看>>
【CSS】使用CSS改变超链接样式
查看>>
HTC T328W刷机包 仿三星S5 UI美化 精简 S5落下
查看>>
spring AOP面向切面编程学习笔记
查看>>
Proftp设置虚拟用户(转)
查看>>
基于tiny4412的Linux内核移植(支持device tree)(二)
查看>>