Description
A given n circle in a planar Cartesian coordinate system. It is known that these circles 22 have no intersection, that is, the relationship between two circles only exists and contains. To find the different faces of these circles
Product and. The area is calculated as an area within an odd number of circles, and is not considered when an area is within an even number of circles. Input
The first line contains a positive integer n, which represents the number of circles. The next n lines, 3 nonnegative integers per line, x,y,r a center point at (x, y), radius r
Round. Guaranteed |x|,|y|,≤10^8,r>0,n<=200000output
Only one line of integers, representing the Xor area of all circles and dividing by Pi Pi results.
Sample Input2
0 0 1
0 0 2Sample Output3This problem is a template problem, a classic problem.
1#include <algorithm>2#include <iostream>3#include <cstring>4#include <cstdio>5#include <cmath>6#include <Set>7 8#include <cassert>9 using namespacestd;Ten Const intn=200010, m=600010; One intn,px[n],py[n],r[n],top,t; A Long LongSqrLong LongA) {returnA *A;} - structpoint{ - intID,X,TP; theFriendBOOL operator<(point X,point y) { - DoubleA=py[x.id]+x.tp*sqrt (Sqr (r[x.id])-SQR (tpx[x.id])); - DoubleB=py[y.id]+y.tp*sqrt (Sqr (r[y.id])-SQR (tpx[y.id])); - if(a!=b)returnA<b;assert (x.id==y.id);returnx.tp<y.tp; + } - }st[m]; + BOOLCMP (point A,point b) { A returna.x<b.x; at } - intRes[n]; - Set<Point>s; - Set<Point>:: iterator it; - Long Longans; - in - intMain () { toFreopen ("circle.in","R", stdin); +Freopen ("Circle.out","W", stdout); -scanf"%d",&n); the for(intI=1; i<=n;i++){ *scanf"%d%d%d",&px[i],&py[i],&r[i]); $St[++top]= (point) {i,px[i]-r[i],1};Panax NotoginsengSt[++top]= (point) {i,px[i]+r[i],-1}; - } the +Sort (st+1, st+top+1, CMP); A for(intI=1; i<=top;i++){ thePoint X=st[i]; t=x.x; + if(x.tp==1){ -It=s.upper_bound (point) {x.id,0,1}); $ if(It==s.end ()) res[x.id]=1; $ Else{ -Point y=*it; - if(y.tp==1) res[x.id]=-Res[y.id]; the Elseres[x.id]=Res[y.id]; - }WuyiS.insert (point) {x.id,0,-1}); theS.insert (point) {x.id,0,1}); - } Wu Else{ -S.erase (point) {x.id,0,-1}); AboutS.erase (point) {x.id,0,1}); $ } - } - for(intI=1; i<=n;i++) -ans+=res[i]*Sqr (R[i]); Aprintf"%lld\n", ans); + return 0; the}
Counting method (scan line): Jloi 2016-Circle XOR