// ACM-ICPC‘“ΰ—\‘I2012 E. ½’†Œo˜H #include #include #include #include using namespace std; const double EPS = 1e-10; typedef complex P; typedef pair circle; struct L { P p, q; L(P p, P q) : p(p), q(q) {} }; double cross(P a, P b) { return imag(conj(a)*b); } bool ssIntersect(L a, L b){ if(abs(imag((a.q-a.p)/(b.q-b.p))) &res, circle c1, circle c2){ double r1 = c1.second; double r2 = c2.second; double r3 = abs(c1.first-c2.first); double rc = (r3*r3+r1*r1-r2*r2)/(2*r3); double rs = sqrt(r1*r1-rc*rc); P dif = (c2.first-c1.first)/r3; res.push_back(c1.first+dif*P(rc, rs)); res.push_back(c1.first+dif*P(rc,-rs)); } int main(){ int n; while(cin >> n, n){ vector vc(n); for(int i=0;i> x >> y >> r; vc[i] = make_pair(P(x,y), r); } vector

vp; vp.push_back(vc[0].first); for(int i=0;i+1 dist(2*n, 1e12); dist[0] = 0; for(int i=0;i<2*n;i++){ for(int j=i+1;j<2*n;j++){ bool ok = true; for(int k=(i+1)/2+1;ok && k<(j+1)/2;k++) ok &= ssIntersect(L(vp[i], vp[j]), L(vp[2*k-1], vp[2*k])); if(ok) dist[j] = min(dist[j], dist[i]+abs(vp[i]-vp[j])); } } printf("%.8lf\n", dist[2*n-1]); } }