#include #include #include #include #include #include using namespace std; #define POW2(x) ( (x) * (x) ) class Cell{ public: double x, y, z, r; Cell(double x_, double y_, double z_, double r_) : x(x_), y(y_), z(z_), r(r_){} void dump(){ cout << "x:" << x << " y:" << y << " z:" << z << " r:" << r << endl; } }; int n; vector cells; vector > costs; vector > groups; double direct_cost(int i1, int i2){ if (i1 == i2) return 0.0; Cell& c1 = cells[i1]; Cell& c2 = cells[i2]; double d = sqrt(POW2(c1.x-c2.x) + POW2(c1.y-c2.y) + POW2(c1.z-c2.z)) - c1.r - c2.r; // c1.dump(); //c2.dump(); // cout << "makes distance " << d << endl; if (d <= 0) return 0; else return d; } double solve(){ groups.clear(); costs.clear(); costs.resize(n); for (int i=0; i > gcost; gcost.resize(nGroups); for (int i=0; i >& ccc = costs; double d = 0.0; vector aho; aho.push_back(0); while (aho.size() < nGroups){ double min_cost = DBL_MAX; int min_i = -1; for (int i=0; i cost){ min_cost = cost; min_i = j; } } } } aho.push_back(min_i); d += min_cost; } return d; } int main(){ for ( ; ; ){ cin >> n; if (!n) break; cells.clear(); for (int i=0; i> x >> y >> z >> r; cells.push_back(Cell(x, y, z, r)); } printf("%0.3f\n", solve()); } return 0; }