Educational Codeforces Round 2 D. Area of Two Circles' Intersection
来源:互联网 发布:java打印杨辉三角10行 编辑:程序博客网 时间:2024/04/28 01:57
D. Area of Two Circles' Intersection
题目链接:点击打开链接
题意:求两个圆的相交面积;
思路: 大家都知道两圆的位置关系有五种:
①两圆外离 d>R+r
②两圆外切 d=R+r
③两圆相交 R-r<d<R+r(R>r)
④两圆内切 d=R-r(R>r)
⑤两圆内含d<R-r(R>r)
按着分类来做即可 我把外切和外离,内切和内含放在一起,方便计算;
此题不能用海伦公式来求面积,会丢失精度,还有一定要用 long daouble 型;
代码如下:
#include<bits/stdc++.h>using namespace std;typedef long double ld;#define pi acos(-1)struct point {ld x,y;};ld dis(point a,point b){return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}int main(){point a,b;ld r1,r2;while(cin>>a.x>>a.y>>r1){cin>>b.x>>b.y>>r2;ld d=dis(a,b);//printf("%lf %lf %lf\n",fabs(r1-r2),(r1+r2),d);if(d>=r1+r2){printf("0.000000\n");}else if((d>fabs(r1-r2))&&(d<(r1+r2))){//double p=(r1+r2+d)/2.0;//double s=sqrt(p*(p-r1)*(p-r2)*(p-d));ld a=(r2*r2+d*d-r1*r1)/(2*r2*d);ld b=(r1*r1+d*d-r2*r2)/(2*r1*d);ld s1=acos(a) * r2 * r2;ld s2=acos(b) * r1 * r1;ld s=sin(acos(a))*cos(acos(a))*r2*r2+sin(acos(b))*cos(acos(b))*r1*r1;//cout<<(s2+s1-s)<<endl;printf("%.6f\n",(double) (s2+s1-s));}else{ld r=min(r1,r2);printf("%.6f\n",(double) (r*r*pi));}}return 0;}
0 0
- Educational Codeforces Round 2 D. Area of Two Circles' Intersection
- Educational Codeforces Round 2D. Area of Two Circles' Intersection
- Educational Codeforces Round 2 D. Area of Two Circles' Intersection
- 【Educational Codeforces Round 2D】【计算几何 圆面积交 模板】Area of Two Circles' Intersection
- Educational Codeforces Round 2 D.Area of Two Circles' Intersection(计算几何)
- Educational Codeforces Round 2 D - Area of Two Circles' Intersection(两圆交面积)
- Educational Codeforces Round 2D. Area of Two Circles' Intersection(计算几何+圆相交的面积)
- codeforces 600D. Area of Two Circles' Intersection【几何】
- CodeForces 600D Area of Two Circles' Intersection 圆面积交 (POJ 2546, ZOJ 1597)
- CF 600D(Area of Two Circles' Intersection-2圆面积并)
- Educational Codeforces Round 6 D. Professor GukiZ and Two Arrays
- Educational Codeforces Round 15 B. Powers of Two
- Educational Codeforces Round 15, problem: (B) Powers of Two
- Educational Codeforces Round 15 B. Powers of Two (数学)
- Educational Codeforces Round 15 B Powers of Two
- Codeforces Educational Round 2 D题
- Educational Codeforces Round 4 D. The Union of k-Segments
- Educational Codeforces Round 11-D. Number of Parallelograms
- js检测上传文件大小(ie中判断文件上传兼容)
- 单片机学习(一)__led灯
- 浏览器和服务器在基于https进行请求链接到数据传输过程中,用到了如下哪些技术
- QT 5.8 新特性
- android 内外置SD卡的研究
- Educational Codeforces Round 2 D. Area of Two Circles' Intersection
- 【虚拟按键】虚拟键适配PopupWindow显示位置
- 【NOIP模拟】千帆渡
- 标注文件格式转换功能的简单实现
- JavaScript强化教程 —— Cocos2d-JS自动JSB绑定规则修改
- 1041. Be Unique (20)
- 文件
- gem5模拟器安装
- java常用的数组、字符串、集合操作以及数据结构与算法基本知识