1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
|
#include<bits/stdc++.h> using namespace std; #define debug(x) cerr << #x << ": " << (x) << endl #define rep(i,a,b) for(int i=(a);i<=(b);i++) #define dwn(i,a,b) for(int i=(a);i>=(b);i--) #define SZ(a) ((int) (a).size()) #define pb push_back #define all(x) (x).begin(), (x).end() #define x first #define y second using pii = pair<int, int>; using ll = long long; inline void read(int &x){ int s=0; x=1; char ch=getchar(); while(ch<'0' || ch>'9') {if(ch=='-')x=-1;ch=getchar();} while(ch>='0' && ch<='9') s=(s<<3)+(s<<1)+ch-'0',ch=getchar(); x*=s; }
using db = double;
const int N=10; const db eps=1e-10;
int sign(db a){ return a<-eps? -1: a>eps; }
int cmp(db x, db y){ return sign(x-y); }
struct P{ db x, y; P(){} P(db x, db y): x(x), y(y){} P operator + (P p){ return {x+p.x, y+p.y}; } P operator - (P p){ return {x-p.x, y-p.y}; } P operator * (db d){ return {x*d, y*d}; } P operator / (db d){ return {x/d, y/d}; } db abs(){ return sqrt(abs2()); } db abs2(){ return x*x+y*y; } P rot90(){ return P(-y, x); } P unit(){ return *this/abs(); } db dis(P p){ return (*this-p).abs(); } bool operator < (const P &o){ return cmp(x, o.x)? x<o.x: y<o.y; } };
struct C{ P o; db r; void read(){ cin>>o.x>>o.y>>r; } };
vector<P> isCC(C c1, C c2){ db d=c1.o.dis(c2.o); db r1=c1.r, r2=c2.r; if(cmp(d, r1+r2)==1) return {}; if(cmp(d, abs(r1-r2))==-1) return {}; d=min(d, r1+r2); db y=(r1*r1 + d*d - r2*r2) / (d*2); db x=sqrt(r1*r1-y*y); P dr=(c2.o-c1.o).unit(); P q1=c1.o+dr*y, q2=dr.rot90()*x; return {q1-q2, q1+q2}; }
bool PonC(P p, C c){ return cmp(c.r, p.dis(c.o))? 0: 1; }
struct DSU{ int n; int f[N]; void init(int _n){ n=_n; rep(i, 1, n){ f[i]=i; } } int find(int x){ return x==f[x]? x: f[x]=find(f[x]); } void merge(int u, int v){ u=find(u), v=find(v); if(u==v) return; f[u]=v; } int total(){ int cnt=0; rep(i, 1, n) cnt+=(i==find(i)); return cnt; } }dsu;
int n; C c[N];
void solve(){ cin>>n; rep(i, 1, n) c[i].read(); vector<P> b; dsu.init(n); rep(i, 1, n) rep(j, i+1, n){ auto tmp=isCC(c[i], c[j]); for(auto e: tmp) b.pb(e); if(tmp.size()){ dsu.merge(i, j); } } { sort(all(b)); vector<P> nb; rep(i, 0, SZ(b)-1){ bool dup=false; if(i && !cmp(b[i].x, b[i-1].x) && !cmp(b[i].y, b[i-1].y)){ dup=true; } if(!dup) nb.pb(b[i]); } b=nb; } int C=dsu.total(); int V=SZ(b); int E=0; rep(i, 1, n){ for(auto e: b){ if(PonC(e, c[i])) ++E; } } cout<<C+1+E-V<<"\n"; }
signed main(){ solve(); return 0; }
|