codeforces 600D. Area of Two Circles' Intersection【几何】

/*
    题意:给你两个圆的圆心和半径,求出两个圆相交的面积
    类型:几何
    分析:直接套模板0.0
    感悟:提交C++在第36个样例蜜汁损失了精度,WA了数次之后,提交了一下G++,过了...
          哪位大神能给小弟指点一下。不胜感激。。
*/
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<iomanip>
using namespace std;
typedef long double ld;
typedef long long ll;
ld x[2],y[2],r[2];
inline ld sqr(ld x){ return x*x; }
inline ll sqrl(ll x) { return x*x; }
inline ld fcos(ld a, ld b, ld c){
    return acosl((a*a+b*b-c*c)/(2*a*b));
}
inline ld cut(ld ang, ld r){
    ld s1 = ang*r*r;
    ld s2 = sinl(ang)*cosl(ang)*r*r;
    return s1 - s2;
}
const ld pi = acosl(-1);
ld solve(){
    if(r[0] > r[1]){
        swap(r[0],r[1]);
        swap(x[0],x[1]);
        swap(y[0],y[1]);
    }
    ll dx = x[0]-x[1], dy = y[0]-y[1];
    ll ds = sqrl(dx)+sqrl(dy);
    if(ds >= sqrl(r[0]+r[1])) return 0;
    ld d = sqrtl(ds);
    if(d+r[0] <= r[1]) return sqr(r[0])*pi;
    ld ang[2];
    ang[0] = fcos(d,r[0],r[1]);
    ang[1] = fcos(d,r[1],r[0]);
    return cut(ang[0],r[0]) + cut(ang[1],r[1]);
}
int main()
{
    cin>>x[0]>>y[0]>>r[0]>>x[1]>>y[1]>>r[1];
    cout<<setprecision(8)<<solve()<<endl;
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值