首页 > 其他 > 详细

B - Area of Two Circles' Intersection CodeForces - 600D

时间:2019-12-03 00:14:00      阅读:90      评论:0      收藏:0      [点我收藏+]

题目链接:https://codeforces.com/problemset/problem/600/D

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 exceed 10 - 6.

Examples

Input
0 0 4
6 0 4
Output
7.25298806364175601379
Input
0 0 5
11 0 5
Output
0.00000000000000000000
题目大意:求两个圆相交的面积
思路:讨论分相交 相离 包含三种情况即可
看代码:
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<cmath>
using namespace std;
typedef long double ld;
const int maxn=1e5+5;
const int maxm=1e5+10;
const ld Pi=acos(-1);
int main()
{
    ld x1,y1,r1,x2,y2,r2;
    cin>>x1>>y1>>r1>>x2>>y2>>r2;
    ld d=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
    if(d>=r1+r2) printf("0.000000000000\n");
    else if(d<=fabs(r1-r2))
    {
        printf("%.20Lf\n",min(Pi*r1*r1,Pi*r2*r2));
    }
    else
    {
        ld c=(r2*r2+d*d-r1*r1)/(2*r2*d);//cos
        ld cc=acos(c);//角度
        ld sarea=cc*2/(2)*r2*r2;
        ld tarea=r2*c*r2*sin(cc);

        ld c1=(r1*r1+d*d-r2*r2)/(2*r1*d);//cos
        ld cc1=acos(c1);//角度
        ld sarea1=cc1*2/(2)*r1*r1;
        ld tarea1=r1*c1*r1*sin(cc1);
        printf("%.20Lf\n",(sarea1-tarea1)+(sarea-tarea));
    }

    return 0;
}
/**

*/

 

B - Area of Two Circles' Intersection CodeForces - 600D

原文:https://www.cnblogs.com/caijiaming/p/11973181.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!