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;
    }
    /**
    
    */
    当初的梦想实现了吗,事到如今只好放弃吗~
  • 相关阅读:
    高并发场景 LVS 安装及keepalived的应用
    使用nginx作为http/https正向代理
    Spring5【七】Spring 整合 MyBatis
    Spring5【六】代理模式及 AOP
    MyBatis 配置模板
    Spring5【五】Bean 的自动装配及注解开发
    Spring5【四】依赖注入(DI)
    Spring5【三】IoC 创建对象的方式及配置说明
    Spring5【一】Spring 简介
    MyBatis【七】缓存
  • 原文地址:https://www.cnblogs.com/caijiaming/p/11973181.html
Copyright © 2011-2022 走看看