【Educational Codeforces Round 2D】【计算几何 圆面积交 模板】Area of Two Circles' Intersection
2015-11-30 09:28
621 查看
D. Area of Two Circles' Intersection
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
You are given two circles. Find the area of their intersection.
Input
The first line contains three integers x1, y1, r1 ( - 109 ≤ x1, y1 ≤ 109, 1 ≤ r1 ≤ 109)
— the position of the center and the radius of the first circle.
The second line contains three integers x2, y2, r2 ( - 109 ≤ x2, y2 ≤ 109, 1 ≤ r2 ≤ 109)
— the position of the center and the radius of the second circle.
Output
Print the area of the intersection of the circles. The answer will be considered correct if the absolute or relative error doesn't exceed10 - 6.
Sample test(s)
input
output
input
output
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
You are given two circles. Find the area of their intersection.
Input
The first line contains three integers x1, y1, r1 ( - 109 ≤ x1, y1 ≤ 109, 1 ≤ r1 ≤ 109)
— the position of the center and the radius of the first circle.
The second line contains three integers x2, y2, r2 ( - 109 ≤ x2, y2 ≤ 109, 1 ≤ r2 ≤ 109)
— the position of the center and the radius of the second circle.
Output
Print the area of the intersection of the circles. The answer will be considered correct if the absolute or relative error doesn't exceed10 - 6.
Sample test(s)
input
0 0 4 6 0 4
output
7.25298806364175601379
input
0 0 5 11 0 5
output
0.00000000000000000000
#include<stdio.h> #include<iostream> #include<iomanip>//这个库含有setprecision(15)的精度设置 #include<string.h> #include<string> #include<ctype.h> #include<math.h> #include<set> #include<map> #include<vector> #include<queue> #include<bitset> #include<algorithm> #include<time.h> using namespace std; void fre(){freopen("c://test//input.in","r",stdin);freopen("c://test//output.out","w",stdout);} #define MS(x,y) memset(x,y,sizeof(x)) #define MC(x,y) memcpy(x,y,sizeof(x)) #define MP(x,y) make_pair(x,y) #define ls o<<1 #define rs o<<1|1 typedef long long LL; typedef unsigned long long UL; typedef unsigned int UI; template <class T1,class T2>inline void gmax(T1 &a,T2 b){if(b>a)a=b;} template <class T1,class T2>inline void gmin(T1 &a,T2 b){if(b<a)a=b;} const int N=0,M=0,Z=1e9+7,ms63=1061109567; const long double PI=acos(-1.0); struct Round { long double x,y; long double r; long double K(long double x) { return x*x; } long double Dis(Round a,Round b) { return sqrt(K(a.x-b.x)+K(a.y-b.y)); } long double Intersection_area(Round a,Round b) { long double dis=Dis(a,b); if(a.r==0||b.r==0||dis>=a.r+b.r)return 0; else if(dis<=fabs(a.r-b.r))return PI*K(min(a.r,b.r)); else { long double angA=2*acos( (K(a.r)+K(dis)-K(b.r))/(2*a.r*dis) ); long double angB=2*acos( (K(b.r)+K(dis)-K(a.r))/(2*b.r*dis) ); long double areaA=K(a.r)*(angA-sin(angA))/2; long double areaB=K(b.r)*(angB-sin(angB))/2; return areaA+areaB; } } }a,b; int main() { while(cin>>a.x>>a.y>>a.r>>b.x>>b.y>>b.r) { cout<<setprecision(25)<<a.Intersection_area(a,b); } return 0; } /* ~两圆关系模板,wkc倾力打造~ 类型:两圆之间的关系可能是相离,外切,相交,内切,内含这五种。它们都可以利用圆心距离与半径之间的关系来确定。 设两圆圆心距为dis,两圆半径分别是r0和r1,那么,我们有—— if(dis>r0+r1)then 两圆相离 if(dis==r0+r1)then 两圆外切 if(dis==fabs(r0-r1))then 两圆内切 if(dis<fabs(r0-r1))then 两圆内含 if(dis>fabs(r0-r1)&&dis<r0+r1)then 两圆相切 相离,外切:相交面积为0 内切,内含:相交面积为小圆面积 相交:相交面积可以用扇形面积减去三角形面积求得 特别说明:long double要用cin cout输入输出。用iomanip库中的setprecision(15)输出精度,最高15位。 */
相关文章推荐
- 设计模式之行为型模式 - 调用行为的传递问题
- [div+css]晒晒最新制作专题推广页模板
- 2008大学生入党申请书 模板
- IMAIL多语言模板两套Outlook&Gmail模板下载
- 在PHP中使用模板的方法
- 深入解析php模板技术原理【一】
- Json2Template.js 基于jquery的插件 绑定JavaScript对象到Html模板中
- 在ASP中不用模板生成HTML静态页直接生成.html页面
- C#模板方法模式(Template Method Pattern)实例教程
- javascript文本模板用法实例
- 关于Asp代码与页面的分离模板技术第1/3页
- php模板原理讲解
- 需要使用php模板的朋友必看的很多个顶级PHP模板引擎比较分析
- DataGrid 动态添加模板列 实现代码
- C++模板之特化与偏特化详解
- vs.net2008添加模板方法
- ThinkPHP模板判断输出Empty标签用法详解
- ThinkPHP模板范围判断输出In标签与Range标签用法详解
- thinkphp模板用法和内容输出实例
- thinkphp模板赋值与替换实例简述