/* coder: ACboy date: 2010-3-19 result: AC description: UVa 216 Getting in Line */ #include <iostream> #include <cmath> using namespace std; struct node { double x; double y; }; struct Ans { node a; node b; double dis; }; node input[10]; Ans ans[10]; Ans tempAns[10]; int vis[8]; int everyPos[40320][8]; int temp[8]; int c; int n; void dfs(int pos) { if (pos == n) { for (int i = 0; i < n; i++) { everyPos[c][i] = temp[i]; } c++; } else { for (int j = 0; j < n; j++) if (!vis[j]) { temp[pos] = j; vis[j] = 1; dfs(pos + 1); vis[j] = 0; } } } double getDis(node & a, node & b) { return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)) + 16; } int main() { #ifndef ONLINE_JUDGE freopen("216.txt", "r", stdin); #endif int count = 0; while (cin >> n) { if (n == 0) break; c = 0; memset(vis, 0, sizeof(vis)); dfs(0); int i, j; for (i = 0; i < n; i++) { cin >> input[i].x >> input[i].y; } double min = 1 << 30; for (i = 0; i < c; ++i) { int t = 0; double sum = 0; for (j = 0; j < n - 1; j++) { double tempDis = getDis(input[everyPos[i][j]], input[everyPos[i][j + 1]]); sum += tempDis; tempAns[t].a = input[everyPos[i][j]]; tempAns[t].b = input[everyPos[i][j + 1]]; tempAns[t].dis = tempDis; t++; } if (sum < min) { min = sum; for (int k = 0; k < t; ++k) { ans[k] = tempAns[k]; } } } cout << "**********************************************************" << endl; cout << "Network #" << ++count << endl; for (i = 0; i < n - 1; ++i) { printf("Cable requirement to connect (%.0lf,%.0lf) to (%.0lf,%.0lf) is %.2lf feet./n", ans[i].a.x, ans[i].a.y, ans[i].b.x, ans[i].b.y, ans[i].dis); } printf("Number of feet of cable required is %.2lf./n", min); } return 0; }