CodeForces 600D 圆的面积交

圆的面积交,板题。

#include <bits/stdc++.h>
#define aint(x) x.begin(), x.end()
using namespace std;

typedef long long LL;
const int maxn = 111;

const long double pi = acos(-1.0);
struct Point {
    long double x, y;
    Point(long double x = 0, long double y = 0):x(x),y(y) {};
};

const long double eps = 1e-10;
int dcmp(long double x) {
    if(fabs(x) < eps) return 0; else return x < 0? -1 : 1;
}

long double Dis(Point a, Point b) {
    return sqrt((b.x-a.x)*(b.x-a.x)+(b.y-a.y)*(b.y-a.y));
}

long double AreaOfOverlap(Point c1, long double r1, Point c2, long double r2) {
    long double a = Dis(c1, c2), b = r1, c = r2;
    long double s1 = pi*r1*r1, s2 = pi*r2*r2;
    if(dcmp(a - b - c) >= 0) return 0;
    if(dcmp(a + min(b, c) - max(b, c)) <= 0) return min(s1, s2);
    else {
         long double cta1 = 2*acos((a*a+b*b-c*c)/(2*a*b));
         long double cta2 = 2*acos((a*a+c*c-b*b)/(2*a*c));
         return cta1/(2*pi)*s1-0.5*sin(cta1)*b*b + cta2/(2*pi)*s2-0.5*sin(cta2)*c*c;
    }
}

int main() {
    Point p1, p2;
    long double r1, r2;
    while(cin >> p1.x >> p1.y >> r1) {
        cin >> p2.x >> p2.y >> r2;
        cout<<fixed<<setprecision(10)<<AreaOfOverlap(p1, r1, p2, r2)<<endl;
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值