您的位置:首页 > 其它

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

2016-08-17 15:15 513 查看
/*
题意:给你两个圆的圆心和半径,求出两个圆相交的面积
类型:几何
分析:直接套模板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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: