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;
    }
    /**
    
    */
    当初的梦想实现了吗,事到如今只好放弃吗~
  • 相关阅读:
    LC 774. Minimize Max Distance to Gas Station 【lock,hard】
    LC 272. Closest Binary Search Tree Value II 【lock,hard】
    LC 644. Maximum Average Subarray II 【lock,hard】
    Java --- JSP2新特性
    Java ---Listener监听器
    Java ---Filter过滤器
    Java ---自定义标签(二)
    Java ---自定义标签
    Java ---理解MVC架构
    Java--JDBC连接数据库(二)
  • 原文地址:https://www.cnblogs.com/caijiaming/p/11973181.html
Copyright © 2011-2022 走看看