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
0 0 4
6 0 4
output
7.25298806364175601379
input
0 0 5
11 0 5
output
0.00000000000000000000

题意:求两个圆相交面积,主要问题就是精度的问题;

解决思路:在两个圆心相距很远的时候用两个圆心和一个交点算角度的精度可能不够,可以用两个交点和一个圆心来算比较好;

AC代码:

#include <bits/stdc++.h>
#define pi acos(-1.0)
using namespace std;
long double x1,x2,y2,r1,r2,y;
long double area(){
long double d=sqrt((x1-x2)*(x1-x2)+(y-y2)*(y-y2));
if(r1>r2){
long double temp=r1;
r1=r2;
r2=temp;
}
if(r1+r2<=d) return 0;
else if(r2-r1>=d) return pi*r1*r1;
else {
long double a1=acos((r1*r1+d*d-r2*r2)/(2.0*r1*d));
long double a2=acos((r2*r2+d*d-r1*r1)/(2.0*r2*d));
a1*=2;
a2*=2;
return (a1*r1*r1+a2*r2*r2-r1*r1*sin(a1)-r2*r2*sin(a2))/2.0;
}
}
int main()
{
cin>>x1>>y>>r1;
cin>>x2>>y2>>r2;
cout<<fixed<<area()<<endl; return 0;
}

最新文章

  1. 评《撸一段 SQL ? 还是撸一段代码? 》
  2. pycharm配置字体问题
  3. visio调整画布大小和旋转画布(转)
  4. Asp.net 之Application
  5. linux下vim命令详解 转自: zhanglong0426
  6. Spring中Bean的配置:基于注解的方式
  7. 来自Google产品管理和营销高级副总裁Jonathan Rosenberg的42条军规(转)
  8. mv命令
  9. emWin(ucGUI)在PC机上模拟的按键响应多次解决办法 worldsing
  10. Nginx开发从入门到精通
  11. codeforces 432D Prefixes and Suffixes
  12. c++,多继承造成的二义性及解决办法
  13. layer弹出层中H5播放器全屏出错解决 &amp; 属性poster底图占满&lt;video&gt;的方法
  14. Java AOP (1) compile time weaving 【Java 切面编程 (1) 编译期织入】
  15. noip第29课资料
  16. 【网络编程2】网络编程基础-发送ICMP包(Ping程序)
  17. 性能测试需求分析 业务PV量,响应时间、QPS、TPS
  18. 华为S5300系列升级固件S5300SI-V100R005C01SPC100.cc
  19. vue设置多入口教程
  20. scala 学习笔记十二 继承

热门文章

  1. Quartz使用总结(转发:http://www.cnblogs.com/drift-ice/p/3817269.html)
  2. 4.1 使用STM32控制MC20拨打电话
  3. django目录下的路由系统和视图函数
  4. Javascript 广告浮动效果在浏览器中间N秒后移动到右下角
  5. win10 chrome 调试
  6. LeetCode:对角线遍历【498】
  7. 正则表达式test match exec search
  8. Linux用户和用户组管理 用户管理相关命令
  9. 创建Android守护进程(底层服务)【转】
  10. linux学习(rz和sz命令的安装和使用)