zoukankan      html  css  js  c++  java
  • B

    题目链接: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
    ");
        else if(d<=fabs(r1-r2))
        {
            printf("%.20Lf
    ",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
    ",(sarea1-tarea1)+(sarea-tarea));
        }
    
        return 0;
    }
    /**
    
    */
    当初的梦想实现了吗,事到如今只好放弃吗~
  • 相关阅读:
    高效 JavaScript
    什么是QName【转】
    gson的简单使用方法
    SWT的FormLayout
    SWT/JFace常用组件容器类
    更改swing应用程序标题栏默认图标
    面试也是自己对自己的面试
    关于Android图片cache处理方法
    【Java】_2_Java程序入门第二课
    【算法和数据结构】_9_线性结构_队列_续_1
  • 原文地址:https://www.cnblogs.com/caijiaming/p/11973181.html
Copyright © 2011-2022 走看看