|
| 1 | +//#pragma GCC optimize("Ofast") |
| 2 | +//#pragma GCC target("avx,avx2,fma") |
| 3 | + |
| 4 | +#include <bits/stdc++.h> |
| 5 | + |
| 6 | +#define besmellah ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); |
| 7 | +using namespace std; |
| 8 | +typedef long long ll; |
| 9 | +typedef long double ld; |
| 10 | +typedef unsigned long long ull; |
| 11 | +const ll INF = 1e9 + 7; |
| 12 | + |
| 13 | +const int OO = 0x3f3f3f3f; |
| 14 | +const ll LOO = 0x3f3f3f3f3f3f3f3f; |
| 15 | +const ll MOD = 1e9 + 7; |
| 16 | +const ll N = 1e5; |
| 17 | +const double EPS = 1e-6; |
| 18 | +#define M_PI 3.14159265358979323846 |
| 19 | +#define all(a) a.begin(),a.end() |
| 20 | +#define endl '\n' |
| 21 | + |
| 22 | +int lg(int n) { return 31 - __builtin_clz(n); } |
| 23 | + |
| 24 | +const int dx[] = {+0, +0, +1, -1, +1, -1, +1, -1}; |
| 25 | +const int dy[] = {+1, -1, +0, +0, +1, -1, -1, +1}; |
| 26 | +int knightDx[] = {+1, -1, +2, +2, -2, -2, +1, -1}; |
| 27 | +int knightDy[] = {+2, +2, +1, -1, +1, -1, -2, -2}; |
| 28 | +//#define int long long |
| 29 | + |
| 30 | +map<int, pair<double, double>> cor; |
| 31 | +int n; |
| 32 | + |
| 33 | +double solve(int i, int msk, vector<vector<double>> &dp) { |
| 34 | + if (msk == (1 << (2 * n)) - 1)return 0; |
| 35 | + for (int j = 0; j < 2 * n; ++j) { |
| 36 | + if ((1 << j) & msk)continue; |
| 37 | + i = j; |
| 38 | + msk = msk | (1 << j); |
| 39 | + break; |
| 40 | + } |
| 41 | + double &ret = dp[i][msk]; |
| 42 | + if (ret != -1)return ret; |
| 43 | + |
| 44 | + double op1 = OO; |
| 45 | + |
| 46 | + for (int j = 0; j < 2 * n; ++j) { |
| 47 | + if ((1 << j) & msk)continue; |
| 48 | + op1 = min(op1, solve(i, msk | (1 << j), dp) + |
| 49 | + sqrt(abs(cor[i].first - cor[j].first) * abs(cor[i].first - cor[j].first) + |
| 50 | + abs(cor[i].second - cor[j].second) * abs(cor[i].second - cor[j].second))); |
| 51 | + } |
| 52 | + return ret = op1; |
| 53 | +} |
| 54 | + |
| 55 | + |
| 56 | +signed main() { |
| 57 | + besmellah |
| 58 | +//Sky is the limit ❤ |
| 59 | +#ifdef CLION |
| 60 | + freopen("input.txt", "r", stdin); |
| 61 | + freopen("output.txt", "w", stdout); |
| 62 | +#else |
| 63 | + //freopen("", "r", stdin); |
| 64 | +#endif |
| 65 | + int T = 1; |
| 66 | + //cin >> T; |
| 67 | +//remember data type long long or int |
| 68 | + while (T--) { |
| 69 | + int u = 1; |
| 70 | + while (cin >> n and n) { |
| 71 | + vector<vector<double>> dp(2 * n, vector<double>(1 << (2 * n), -1)); |
| 72 | + map<string, int> id; |
| 73 | + cin.ignore(); |
| 74 | + int idd = 0; |
| 75 | + for (int i = 0; i < 2 * n; ++i) { |
| 76 | + string s; |
| 77 | + getline(cin, s); |
| 78 | + string a; |
| 79 | + while (!isdigit(s.front()))a += s.front(), s.erase(s.begin()); |
| 80 | + if (a.back() == ' ')a.pop_back(); |
| 81 | + id[a] = idd++; |
| 82 | + int x = 0; |
| 83 | + while (isdigit(s.front()))x *= 10, x += s.front() - '0', s.erase(s.begin()); |
| 84 | + if (s.front() == ' ')s.erase(s.begin()); |
| 85 | + int y = 0; |
| 86 | + while (isdigit(s.front()))y *= 10, y += s.front() - '0', s.erase(s.begin()); |
| 87 | + cor[id[a]] = {x, y}; |
| 88 | + } |
| 89 | + cout << "Case " << u++ << ": " << fixed << setprecision(2) << solve(0, 0, dp) << endl; |
| 90 | + } |
| 91 | + |
| 92 | + } |
| 93 | +//remember data type long long or int |
| 94 | + |
| 95 | +} |
0 commit comments