1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
| #include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> #include <algorithm> #define MAXN (500 + 5) #define DD double #define pii pair<int, int> const int s = 0, t = 501; using namespace std; struct edg { int from, to; DD cost; edg() {} edg(int a, int b, DD c): from(a), to(b), cost(c) {} }b[MAXN * MAXN]; int fa[MAXN], n, cntb, l; pii a[MAXN]; int find(int x) { return (fa[x] == x) ? x : (fa[x] = find(fa[x])); } void uni(int x, int y) { fa[find(x)] = find(y); } bool cmp(edg x, edg y) { return x.cost < y.cost; } DD caldis(int x0, int y0, int x1, int y1) { return sqrt((x0 - x1) * (x0 - x1) + (y0 - y1) * (y0 - y1)); } void solve() { sort(b + 1, b + cntb + 1, cmp); for (int i = s; i <= t; i++) fa[i] = i; for (int i = 1; i <= cntb; i++) if (find(b[i].from) != find(b[i].to)) { uni(b[i].from, b[i].to); if (find(s) == find(t)) { printf("%.3lf", b[i].cost); return ; } } } int main() { scanf("%d%d", &n, &l); for (int i = 1; i <= n; i++) { scanf("%d%d", &a[i].first, &a[i].second); b[++cntb] = edg(s, i, l - a[i].second); b[++cntb] = edg(t, i, a[i].second); for (int j = 1; j < i; j++) b[++cntb] = edg(i, j, caldis(a[i].first, a[i].second, a[j].first, a[j].second)); }
solve(); return 0; }
|