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;
}

codeforces D. Area of Two Circles' Intersection 计算几何的更多相关文章

  1. codeforces 600D Area of Two Circles' Intersection

    分相离,内含,想交三种情况讨论一下. 主要是精度和数据范围的问题,首先数据用long double,能用整型判断就不要用浮点型. 题目中所给的坐标,半径是整型的,出现卡浮点判断的情况还是比较少的. 最 ...

  2. codeforce--600D - Area of Two Circles' Intersection

    题意:求相交圆的面积.借鉴大神代码,精度超高. #include <fstream> #include <iostream> #include <string> # ...

  3. SPOJ 8073 The area of the union of circles(计算几何の圆并)(CIRU)

    Description You are given N circles and expected to calculate the area of the union of the circles ! ...

  4. Intersection(计算几何)

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

  5. hdu-5120 Intersection(计算几何)

    题目链接: Intersection Time Limit: 4000/4000 MS (Java/Others)     Memory Limit: 512000/512000 K (Java/Ot ...

  6. POJ 1410 Intersection (计算几何)

    题目链接:POJ 1410 Description You are to write a program that has to decide whether a given line segment ...

  7. Codeforces 749B:Parallelogram is Back(计算几何)

    http://codeforces.com/problemset/problem/749/B 题意:已知平行四边形三个顶点,求另外一个顶点可能的位置. 思路:用向量来做. #include <c ...

  8. Codeforces Round #465 &935C. Fifa and Fafa计算几何

    传送门 题意:在平面中,有一个圆,有一个点,问能在这个圆中围出最大的圆的圆心坐标和半径.要求这个最大圆不包含这个点. 思路:比较基础的计算几何,要分三种情况,第一种就是这个点在圆外的情况.第二种是点在 ...

  9. codeforces#1163C2. Power Transmission (Hard Edition)(计算几何)

    题目链接: https://codeforces.com/contest/1163/problem/C2 题意: 给出$n$个点,任意两点连接一条直线,求相交直线的对数 数据范围: $1 \le n ...

随机推荐

  1. 1.5 使用电脑测试MC20的发送英文短信功能

    需要准备的硬件 MC20开发板 1个 https://item.taobao.com/item.htm?id=562661881042 GSM/GPRS天线 1根 https://item.taoba ...

  2. php 计算器的例子

    php实现的计算器的例子,代码如下: <html>     <head>         <title>PHP实现简单计算器-www.jbxue.com</t ...

  3. python2.7升级到python3.6注意事项

    python3.6下载地址:https://www.python.org/downloads/source/ 1.安装依赖包:gcc   openssl-devel.zlib-devel.readli ...

  4. [转]AOP那些学术概念—通知、增强处理连接点(JoinPoint)切面(Aspect)

    AOP那些学术概念—通知.增强处理连接点(JoinPoint)切面(Aspect) 1.我所知道的AOP 初看起来,上来就是一大堆的术语,而且还有个拉风的名字,面向切面编程,都说是OOP的一种有益补充 ...

  5. U-Boot中支持USB

    转载: http://blog.csdn.net/qiurihuanghua/article/details/6234832 今天查看了一下在P4080DS板子的U-Boot中支持USB,主要是加入U ...

  6. Kubernetes Kube-proxy

    Kube-proxy主要负责Service的实现. kube-proxy enables the Kubernetes service abstraction by maintaining netwo ...

  7. jenkins tomcat

    tomcat增加用户配置: <role rolename="tomcat"/> <role rolename="role1"/> < ...

  8. 多校hdu5754(博弈)

    ©此题中在N×M的棋盘中从(1,1)走到(N,M)B先走G后走,谁先到(N,M)谁赢,走法分为4中分别是国际象棋中的国王,车,马,王后的发,在四种走法下谁能赢: 我们依次分析每一种棋子. ①王. 首先 ...

  9. java进阶之-Maven,svn,git,maven合拼多个项目

    git的使用介绍(写很容易懂得哦) maven合拼多个项目(写得很好哦) MAVEN作用:统一开发规范与工具:统一管理jar包 1.下载MAVEN  下载绿色版的面安装 2.环境配置 eclipse想 ...

  10. python 矩阵分成上三角下三角和对角三个矩阵

    diagonal Return specified diagonals. diagflat Create a 2-D array with the flattened input as a diago ...