#include #include #include #include using namespace std; struct Point { double x, y, z, r; Point(double x, double y, double z, double r) { this->x = x; this->y = y; this->z = z; this->r = r; } double distance(const Point& A) const { double ret = (sqrt((A.x - this->x) * (A.x - this->x) + (A.y - this->y) * (A.y - this->y) + (A.z - this->z) * (A.z - this->z)) - (A.r + this->r)); if (ret < 0) { return 0; } else { return ret; } } }; struct P { int index; double d; P(int index, double d) { this->index = index; this->d = d; } bool operator < (const P& p) const { return this->d < p.d; } bool operator == (const P& p) const { return fabsl(this->d - p.d) < 0.0001; } }; int main() { int n; while (cin >> n && n) { vector input; for (int i = 0; i < n; i++) { double x, y, z, r; cin >> x >> y >> z >> r; input.push_back(Point(x, y, z, r)); } int include[n]; memset(include, 0, sizeof(include)); multiset

Q; include[0] = true; for (int i = 0; i < n; i++) { if (include[i]) { continue; } Q.insert(P(i, input[i].distance(input[0]))); } double ans = 0; while (!Q.empty()) { P p = *Q.begin(); Q.erase(Q.begin()); if (include[p.index]) { continue; } ans += p.d; include[p.index] = true; for (int i = 0; i < n; i++) { Q.insert(P(i, input[i].distance(input[p.index]))); } } printf("%.03lf\n", ans); } return 0; }