hdu 5120 Intersection(几何 容斥)
2015-02-05 11:04
501 查看
hdu 5120 Intersection
(a1 - b1) X (a2 - b2)= a1Xa2 - b1Xa2 - a1Xb2 + b1Xb2
#include<cstdio> #include<iostream> #include<string> #include<cstring> #include<algorithm> #include<cmath> #include<map> using namespace std; typedef long long LL; const double eps = 1e-8; const double PI = acos(-1.0); struct _node { double x, y, r; _node(double xx = 0.0, double yy = 0.0, double rr = 0.0):x(xx),y(yy),r(rr) {} double dis(const _node & a) { return sqrt((x-a.x)*(x-a.x) + (y-a.y)*(y-a.y)); } }; inline int zero(double x) { return (x>eps) - (x<-eps); } double cal(_node a, _node b) // 求两圆相交面积 { double d = a.dis(b), r1=a.r, r2=b.r; double a1, a2; if (r1 > r2) swap(r1, r2); if (zero(d - (r1+r2)) >= 0) return 0.0; if (zero(d - (r2 - r1)) <= 0) return PI*r1*r1; a1=acos((r1*r1+d*d-r2*r2)/(2.0*r1*d)); a2=acos((r2*r2+d*d-r1*r1)/(2.0*r2*d)); return (a1*r1*r1+a2*r2*r2-r1*d*sin(a1)); } int main() { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); #endif int t; double rr, r; double x1, x2, y1, y2; scanf("%d", &t); for (int _ =1; _ <= t; ++_) { printf("Case #%d: ", _); scanf("%lf%lf", &r, &rr); scanf("%lf%lf%lf%lf", &x1, &y1, &x2, &y2); printf("%.6lf\n", cal(_node(x1,y1,rr), _node(x2,y2,rr)) - cal(_node(x1,y1,rr), _node(x2,y2,r)) - cal(_node(x1,y1,r), _node(x2,y2,rr)) + cal(_node(x1,y1,r), _node(x2,y2,r))); } return 0; }
相关文章推荐
- HDU 5120 Intersection(计算几何)
- 计算几何(容斥原理,圆交):HDU 5120 Intersection
- HDU 5120 Intersection (计算几何)2014ICPC 北京站现场赛
- HDU-5120-Intersection【几何-相交圆面积】
- HDU - 5120 Intersection(简单几何)——2014ACM/ICPC亚洲区北京站
- HDU 5120 Intersection (计算几何)
- hdu-5120 Intersection(计算几何)
- HDU 5120 Intersection(2014北京赛区现场赛I题 计算几何)
- HDU 5120 Intersection(几何模板题)
- HDU 5120 Intersection
- hdu 5120 Intersection (圆相交面积模板)
- Intersection (hdu-5120)
- HDU —5120 Intersection
- hdu 5120 Intersection(求相交环面积)
- hdu 5120 Intersection (容斥原理+圆的相交面积模板)
- hdu 5120 Intersection(求相交圆的面积)
- HDU 5120 (计算几何+圆相交)
- HDU5120(几何)
- HDU 5120 Intersection (圆的面积交)
- hdu 5120 Intersection 2014ACM/ICPC亚洲区北京站-重现赛