text
stringlengths
49
983k
#include <bits/stdc++.h> struct node { double x, y, z; } po[5005]; double dis[5005]; double getlen(node a, node b) { double len; len = (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y) + (a.z - b.z) * (a.z - b.z); return sqrt(len * 1.0); } int main() { int n; int i, j; int x, y, z; double len, mn; while (scanf("%d", &n) != EOF) { for (i = 1; i <= n; i++) { scanf("%d%d%d", &x, &y, &z); po[i].x = x * 1.0; po[i].y = y * 1.0; po[i].z = z * 1.0; } for (i = 1; i <= n; i++) { dis[i] = getlen(po[1], po[i]); } mn = 999999999.0; for (i = 2; i <= n; i++) for (j = 2; j <= i; j++) { if (i == j) continue; len = dis[i] + dis[j] + getlen(po[i], po[j]); if (len - mn <= 1e-6) mn = len; } printf("%.10lf\n", mn * 1.0 / 2); } return 0; }
#include <bits/stdc++.h> using namespace std; struct point { int x, y, z; double dist(point& p) { return sqrt((double)((p.x - x) * (p.x - x) + (p.y - y) * (p.y - y) + (p.z - z) * (p.z - z))); } }; int N; point P[5005]; double solve() { double res = 1e10; for (int i = 1; i < N; i++) { for (int j = i + 1; j < N; j++) { double per = P[i].dist(P[j]) + P[i].dist(P[0]) + P[j].dist(P[0]); if (per < res) res = per; } } return res / 2.0; } int main() { while (cin >> N) { for (int i = 0; i < N; i++) { cin >> P[i].x >> P[i].y >> P[i].z; } cout << setprecision(12) << solve() << endl; } }
#include <bits/stdc++.h> using namespace std; const int www = 9; const int Size = 10000; char buffer[Size]; int dr[] = {-1, 0, 1, 0}; int dc[] = {0, 1, 0, -1}; const int inf = 0x0fffffff; const int size = 52; long long dp[size][10]; int ar[size]; struct Point { int x, y, z; Point(int x = 0, int y = 0, int z = 0) : x(x), y(y), z(z) {} }; Point operator-(const Point &a, const Point &b) { return Point(a.x - b.x, a.y - b.y, a.z - b.z); } double dist(const Point &a) { return sqrt((double)a.x * a.x + (double)a.y * a.y + (double)a.z * a.z); } int solution(int nTest) { int n; scanf("%d", &n); vector<Point> v; for (int i = 0; i < n; i++) { int x, y, z; scanf("%d%d%d", &x, &y, &z); v.push_back(Point(x, y, z)); } double m = 10e8; Point cent = v[0]; for (int i = 1; i < n; i++) { for (int j = i + 1; j < n; j++) { Point a = v[i], b = v[j]; double x = dist(a - cent); double y = dist(b - cent); double d = dist(a - b); double time = (x + d - y) / 2 + y; m = min(m, time); } } printf("%.7lf\n", m); return 0; } int main() { int i = 0, n = 9999; while (i < n && solution(i)) { i++; } return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 5004; double d[N][N]; int a[N], b[N], c[N]; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d %d %d", &a[i], &b[i], &c[i]); for (int j = 1; j < i; j++) { int x = a[i] - a[j], y = b[i] - b[j], z = c[i] - c[j]; d[j][i] = sqrt(x * x + y * y + z * z); } } double ans = 0x3f3f3f3f; for (int i = 2; i <= n; i++) for (int j = 2; j < i; j++) ans = min(ans, 0.5 * (d[1][i] + d[1][j] + d[j][i])); printf("%.10f\n", ans); }
#include <bits/stdc++.h> #pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,avx,avx2,abm,mmx") #pragma GCC optimize("unroll-loops") using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; template <typename T1, typename T2> inline void chkmin(T1 &x, const T2 &y) { if (x > y) x = y; } template <typename T1, typename T2> inline void chkmax(T1 &x, const T2 &y) { if (x < y) x = y; } struct pt { ll x, y, z; pt() {} }; ld dist(pt a, pt b) { return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y) + (a.z - b.z) * (a.z - b.z)); } ll n; vector<pt> a; void solve() { cin >> n; a.resize(n); for (auto &i : a) cin >> i.x >> i.y >> i.z; ld ans = 1e18; for (ll i = 1; i < n; i++) { for (ll j = 1; j < i; j++) { chkmin(ans, (dist(a[0], a[i]) + dist(a[0], a[j]) + dist(a[i], a[j])) / 2); } } cout.precision(20); cout << ans << endl; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll t = 1; while (t--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; double dist(vector<vector<int> >& v, int i1, int i2) { return sqrt(double(((v[i1][0] - v[i2][0]) * (v[i1][0] - v[i2][0])) + ((v[i1][1] - v[i2][1]) * (v[i1][1] - v[i2][1])) + ((v[i1][2] - v[i2][2]) * (v[i1][2] - v[i2][2])))); } int main() { int n; cin >> n; vector<vector<int> > v(n, vector<int>(3)); for (int i = 0; i < n; ++i) { cin >> v[i][0] >> v[i][1] >> v[i][2]; } double result = 1e100; for (int i = 1; i < n; ++i) { for (int j = 1; j < i; ++j) { result = min(result, (dist(v, 0, i) + dist(v, 0, j) + dist(v, i, j)) / 2.0); } } cout.precision(9); cout << fixed << result << endl; return 0; }
#include <bits/stdc++.h> using namespace std; struct Point { double x, y, z; } P[5678]; int n; double dist(const Point &a, const Point &b) { return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y) + (a.z - b.z) * (a.z - b.z)); } int main() { double minn = 1e100; cin >> n; for (int i = 1; i <= n; i++) { cin >> P[i].x >> P[i].y >> P[i].z; } for (int i = 2; i <= n; i++) { for (int j = i + 1; j <= n; j++) { minn = min(minn, dist(P[1], P[i]) + dist(P[1], P[j]) + dist(P[i], P[j])); } } printf("%.10f\n", minn / 2.0); return 0; }
#include <bits/stdc++.h> using namespace std; struct tdd { int x, y, z; } td[5005]; int n; double res = 1000000000; double sqr(int a) { return a * a; } double kc(int v1, int v2) { return sqrt(sqr(td[v1].x - td[v2].x) + sqr(td[v1].y - td[v2].y) + sqr(td[v1].z - td[v2].z)); } double tinh(int v1, int v2) { double d1 = kc(0, v1); double d2 = kc(0, v2); return max(d1, d2) + (kc(v1, v2) - max(d1 - d2, d2 - d1)) / 2; } int main() { cin >> n; for (int i = 0; i < n; i++) cin >> td[i].x >> td[i].y >> td[i].z; for (int i = 1; i < n; i++) for (int j = i + 1; j < n; j++) res = min(res, tinh(i, j)); printf("%.7lf", res); return 0; }
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:102400000,102400000") const double Pi = acos(-1.0); const double eps = 1e-6; const double Ee = 2.718281828459045235360; const int INF = 0x3f3f3f3f; const long long INFF = 0x3f3f3f3f3f3f3f3fLL; const int MOD = 1000000007; const int dx4[] = {-1, 0, 1, 0}; const int dy4[] = {0, 1, 0, -1}; const int dx8[] = {-1, 0, 1, 0, -1, -1, 1, 1}; const int dy8[] = {0, 1, 0, -1, -1, 1, -1, 1}; const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2}; const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1}; using namespace std; namespace Math { long long GCD(long long a, long long b) { return b ? GCD(b, a % b) : a; } long long extendGCD(long long a, long long b, long long &x, long long &y) { if (!b) return x = 1, y = 0, a; long long res = extendGCD(b, a % b, x, y), tmp = x; x = y, y = tmp - (a / b) * y; return res; } long long power(long long x, long long k) { long long res = 1; while (k) { if (k & 1) res *= x; x *= x, k >>= 1; } return res; } long long powerMod(long long x, long long k, long long m) { long long res = 1; while (x %= m, k) { if (k & 1) res *= x, res %= m; x *= x, k >>= 1; } return res; } long long inverse(long long a, long long p, long long t = 1) { long long pt = power(p, t); long long x, y; y = extendGCD(a, pt, x, y); return x < 0 ? x += pt : x; } long long linearCongruence(long long a, long long b, long long p, long long q) { long long x, y; y = extendGCD(p, q, x, y); while (b < a) b += q / y; x *= b - a, x = p * x + a, x %= p * q; if (x < 0) x += p * q; return x; } const int PRIMERANGE = 1000000; int prime[PRIMERANGE + 1]; int mobius[PRIMERANGE + 1]; int getPrime() { memset(prime, 0, sizeof(int) * (PRIMERANGE + 1)); memset(mobius, 0, sizeof(mobius)); mobius[1] = 1; for (int i = 2; i <= PRIMERANGE; i++) { if (!prime[i]) prime[++prime[0]] = i, mobius[i] = -1; for (int j = 1; j <= prime[0] && prime[j] <= PRIMERANGE / i; j++) { prime[prime[j] * i] = 1; if (i % prime[j] == 0) break; else mobius[i * prime[j]] = -mobius[i]; } } return prime[0]; } int factor[100][3], facCnt; int getFactors(int x) { facCnt = 0; int tmp = x; for (int i = 1; prime[i] <= tmp / prime[i]; i++) { factor[facCnt][1] = 1, factor[facCnt][2] = 0; if (tmp % prime[i] == 0) factor[facCnt][0] = prime[i]; while (tmp % prime[i] == 0) factor[facCnt][2]++, factor[facCnt][1] *= prime[i], tmp /= prime[i]; if (factor[facCnt][1] > 1) facCnt++; } if (tmp != 1) factor[facCnt][0] = tmp, factor[facCnt][1] = tmp, factor[facCnt++][2] = 1; return facCnt; } long long combinationModP(long long n, long long k, long long p) { if (k > n) return 0; if (n - k < k) k = n - k; long long a = 1, b = 1, x, y; int pcnt = 0; for (int i = 1; i <= k; i++) { x = n - i + 1, y = i; while (x % p == 0) x /= p, pcnt++; while (y % p == 0) y /= p, pcnt--; x %= p, y %= p, a *= x, b *= y; b %= p, a %= p; } if (pcnt) return 0; extendGCD(b, p, x, y); if (x < 0) x += p; a *= x, a %= p; return a; } long long inv[100005]; long long ba[100005]; long long rba[100005]; void Init_Com() { inv[0] = inv[1] = 1; ba[0] = ba[1] = 1; rba[0] = rba[1] = 1; for (int i = 2; i < 100005; i++) { inv[i] = ((MOD - MOD / i) * inv[MOD % i]) % MOD; ba[i] = (ba[i - 1] * i) % MOD; rba[i] = (rba[i - 1] * inv[i]) % MOD; } } long long C(int n, int m) { return (ba[n] * rba[m] % MOD) * rba[n - m] % MOD; } int fib[1000000]; int Fib(int a, int b, int n) { if (n == 0) return a; if (n == 1) return b; return (a * fib[n - 1] % MOD + b * fib[n] % MOD) % MOD; } }; // namespace Math namespace Geo { const double eps = 1e-9; int dblcmp(double d) { return d < -eps ? -1 : d > eps; } struct Point { double x, y; Point() {} Point(double _x, double _y) : x(_x), y(_y){}; void input() { scanf("%lf%lf", &x, &y); } void output() { printf("%.2f %.2f\n", x, y); } bool operator==(Point a) const { return dblcmp(a.x - x) == 0 && dblcmp(a.y - y) == 0; } bool operator<(Point a) const { return dblcmp(a.x - x) == 0 ? dblcmp(y - a.y) < 0 : x < a.x; } double len() { return hypot(x, y); } double len2() { return x * x + y * y; } double distance(Point p) { return hypot(x - p.x, y - p.y); } double distance2(Point p) { return ((x - p.x) * (x - p.x)) + ((y - p.y) * (y - p.y)); } Point add(Point p) { return Point(x + p.x, y + p.y); } Point operator+(const Point &p) const { return Point(x + p.x, y + p.y); } Point sub(Point p) { return Point(x - p.x, y - p.y); } Point operator-(const Point &p) const { return Point(x - p.x, y - p.y); } Point mul(double b) { return Point(x * b, y * b); } Point div(double b) { return Point(x / b, y / b); } double dot(Point p) { return x * p.x + y * p.y; } double operator*(const Point &p) const { return x * p.x + y * p.y; } double det(Point p) { return x * p.y - y * p.x; } double operator^(const Point &p) const { return x * p.y - y * p.x; } double rad(Point a, Point b) { Point p = *this; return fabs(atan2(fabs(a.sub(p).det(b.sub(p))), a.sub(p).dot(b.sub(p)))); } Point trunc(double r) { double l = len(); if (!dblcmp(l)) return *this; r /= l; return Point(x * r, y * r); } Point rotleft() { return Point(-y, x); } Point rotright() { return Point(y, -x); } Point rotate(Point p, double angle) { Point v = this->sub(p); double c = cos(angle), s = sin(angle); return Point(p.x + v.x * c - v.y * s, p.y + v.x * s + v.y * c); } }; struct Line { Point a, b; }; }; // namespace Geo namespace BigNum { class BigInteger { private: int a[10010]; int length; public: BigInteger() { length = 1; memset(a, 0, sizeof(a)); } BigInteger(const int); BigInteger(const char *); BigInteger(const BigInteger &); BigInteger &operator=(const BigInteger &); friend istream &operator>>(istream &, BigInteger &); friend ostream &operator<<(ostream &, BigInteger &); BigInteger operator+(const BigInteger &) const; BigInteger operator-(const BigInteger &) const; BigInteger operator*(const BigInteger &) const; BigInteger operator/(const int &) const; BigInteger operator^(const int &) const; int operator%(const int &) const; bool operator>(const BigInteger &T) const; bool operator>(const int &t) const; void print(); }; BigInteger::BigInteger(const int b) { int c, d = b; length = 0; memset(a, 0, sizeof(a)); while (d > 9999) { c = d - (d / (9999 + 1)) * (9999 + 1); d = d / (9999 + 1); a[length++] = c; } a[length++] = d; } BigInteger::BigInteger(const char *s) { memset(a, 0, sizeof(a)); int L = strlen(s); length = L / 4; if (L % 4) length++; int index = 0; for (int i = L - 1; i >= 0; i -= 4) { int t = 0; int k = i - 4 + 1; if (k < 0) k = 0; for (int j = k; j <= i; ++j) t = t * 10 + s[j] - '0'; a[index++] = t; } } BigInteger::BigInteger(const BigInteger &T) : length(T.length) { memset(a, 0, sizeof(a)); for (int i = 0; i < length; i++) a[i] = T.a[i]; } BigInteger &BigInteger::operator=(const BigInteger &n) { length = n.length; memset(a, 0, sizeof(a)); for (int i = 0; i < length; i++) a[i] = n.a[i]; return *this; } istream &operator>>(istream &in, BigInteger &b) { char ch[1010 * 4]; in >> ch; int i = -1, L = strlen(ch), count = 0, sum = 0; for (i = L - 1; i >= 0;) { sum = 0; int t = 1; for (int j = 0; j < 4 && i >= 0; j++, i--, t *= 10) { sum += (ch[i] - '0') * t; } b.a[count] = sum; count++; } b.length = count++; return in; } ostream &operator<<(ostream &out, BigInteger &b) { cout << b.a[b.length - 1]; for (int i = b.length - 2; i >= 0; i--) { cout.width(4); cout.fill('0'); cout << b.a[i]; } return out; } BigInteger BigInteger::operator+(const BigInteger &T) const { BigInteger t(*this); int big; big = T.length > length ? T.length : length; for (int i = 0; i < big; ++i) { t.a[i] += T.a[i]; if (t.a[i] > 9999) { t.a[i + 1]++; t.a[i] -= 9999 + 1; } } if (t.a[big] != 0) t.length = big + 1; else t.length = big; return t; } BigInteger BigInteger::operator-(const BigInteger &T) const { int big; bool flag; BigInteger t1, t2; if (*this > T) { t1 = *this; t2 = T; flag = 0; } else { t1 = T; t2 = *this; flag = 1; } big = t1.length; for (int i = 0; i < big; ++i) { if (t1.a[i] < t2.a[i]) { int j = i + 1; while (t1.a[j] == 0) j++; t1.a[j--]--; while (j > i) t1.a[j--] += 9999; t1.a[i] += 9999 + 1 - t2.a[i]; } else t1.a[i] -= t2.a[i]; } t1.length = big; while (t1.a[t1.length - 1] == 0 && t1.length > 1) { t1.length--; big--; } if (flag) t1.a[big - 1] = 0 - t1.a[big - 1]; return t1; } BigInteger BigInteger::operator*(const BigInteger &T) const { BigInteger ret; int i, j, temp, temp1; for (i = 0; i < length; ++i) { int up = 0; for (j = 0; j < T.length; ++j) { temp = a[i] * T.a[j] + ret.a[i + j] + up; if (temp > 9999) { temp1 = temp - temp / (9999 + 1) * (9999 + 1); up = temp / (9999 + 1); ret.a[i + j] = temp1; } else { up = 0; ret.a[i + j] = temp; } } if (up != 0) ret.a[i + j] = up; } ret.length = i + j; while (ret.a[ret.length - 1] == 0 && ret.length > 1) ret.length--; return ret; } BigInteger BigInteger::operator/(const int &b) const { BigInteger ret; int down = 0; for (int i = length - 1; i >= 0; --i) { ret.a[i] = (a[i] + down * (9999 + 1)) / b; down = a[i] + down * (9999 + 1) - ret.a[i] * b; } ret.length = length; while (ret.a[ret.length - 1] == 0 && ret.length > 1) ret.length--; return ret; } int BigInteger::operator%(const int &b) const { long long d = 0; for (int i = length - 1; i >= 0; --i) { d = ((d * (9999 + 1)) % b + a[i]) % b; } return (int)d; } BigInteger BigInteger::operator^(const int &n) const { BigInteger t, ret(1); if (n < 0) exit(-1); if (n == 0) return 1; if (n == 1) return *this; int m = n; while (m > 1) { t = *this; int i; for (i = 1; (i << 1) <= m; i <<= 1) { t = t * t; } m -= i; ret = ret * t; if (m == 1) ret = ret * (*this); } return ret; } bool BigInteger::operator>(const BigInteger &T) const { int ln; if (length > T.length) return true; else if (length == T.length) { ln = length - 1; while (a[ln] == T.a[ln] && ln >= 0) ln--; if (ln >= 0 && a[ln] > T.a[ln]) return true; else return false; } else return false; } bool BigInteger::operator>(const int &t) const { BigInteger b(t); return *this > b; } void BigInteger::print() { printf("%d", a[length - 1]); for (int i = length - 2; i >= 0; --i) { printf("%04d", a[i]); } puts(""); } }; // namespace BigNum namespace IO_Optimize { template <class T> inline T &RD(T &); template <class T> inline T &RDD(T &); inline long long RD() { long long x; return RD(x); } inline long long RDD() { long long x; return RDD(x); } inline double &RF(double &); inline double RF() { double x; return RF(x); } template <class T0, class T1> inline T0 &RD(T0 &x0, T1 &x1) { RD(x0), RD(x1); return x0; } template <class T0, class T1, class T2> inline T0 &RD(T0 &x0, T1 &x1, T2 &x2) { RD(x0), RD(x1), RD(x2); return x0; } template <class T0, class T1, class T2, class T3> inline T0 &RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3) { RD(x0), RD(x1), RD(x2), RD(x3); return x0; } template <class T0, class T1, class T2, class T3, class T4> inline T0 &RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4) { RD(x0), RD(x1), RD(x2), RD(x3), RD(x4); return x0; } template <class T0, class T1, class T2, class T3, class T4, class T5> inline T0 &RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5) { RD(x0), RD(x1), RD(x2), RD(x3), RD(x4), RD(x5); return x0; } template <class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline T0 &RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5, T6 &x6) { RD(x0), RD(x1), RD(x2), RD(x3), RD(x4), RD(x5), RD(x6); return x0; } template <class T0, class T1> inline void RDD(T0 &a, T1 &b) { RDD(a), RDD(b); } template <class T0, class T1, class T2> inline void RDD(T0 &a, T1 &b, T2 &c) { RDD(a), RDD(b), RDD(c); } inline double &RF(double &a, double &b) { RF(a), RF(b); return a; } inline double &RF(double &a, double &b, double &c) { RF(a), RF(b), RF(c); return a; } inline double &RF(double &a, double &b, double &c, double &d) { RF(a), RF(b), RF(c), RF(d); return a; } inline double &RF(double &a, double &b, double &c, double &d, double &e) { RF(a), RF(b), RF(c), RF(d), RF(e); return a; } inline double &RF(double &a, double &b, double &c, double &d, double &e, double &f) { RF(a), RF(b), RF(c), RF(d), RF(e), RF(f); return a; } inline double &RF(double &a, double &b, double &c, double &d, double &e, double &f, double &g) { RF(a), RF(b), RF(c), RF(d), RF(e), RF(f), RF(g); return a; } template <class T> inline T &RD(T &x) { char c; while (!isdigit((c = getchar()))) ; x = c - '0'; while (isdigit((c = getchar()))) x = x * 10 + c - '0'; return x; } template <class T> inline T &RDD(T &x) { char c; while ((c = getchar()), c != '-' && !isdigit(c)) ; if (c == '-') { x = '0' - (c = getchar()); while (isdigit((c = getchar()))) x = x * 10 + '0' - c; } else { x = c - '0'; while (isdigit((c = getchar()))) x = x * 10 + c - '0'; } return x; } inline double &RF(double &x) { char c; while ((c = getchar()), c != '-' && c != '.' && !isdigit(c)) ; if (c == '-') if ((c = getchar()) == '.') { x = 0; double l = 1; while (isdigit((c = getchar()))) l /= 10, x = x * 10 + '0' - c; x *= l; } else { x = '0' - c; while (isdigit((c = getchar()))) x = x * 10 + '0' - c; if (c == '.') { double l = 1; while (isdigit((c = getchar()))) l /= 10, x = x * 10 + '0' - c; x *= l; } } else if (c == '.') { x = 0; double l = 1; while (isdigit((c = getchar()))) l /= 10, x = x * 10 + c - '0'; x *= l; } else { x = c - '0'; while (isdigit((c = getchar()))) x = x * 10 + c - '0'; if (c == '.') { double l = 1; while (isdigit((c = getchar()))) l /= 10, x = x * 10 + c - '0'; x *= l; } } return x; } }; // namespace IO_Optimize namespace Debug { void out(int *s, int n) { for (int i = 0; i <= n; i++) printf(i < n ? "%d " : "%d(--)\n", s[i]); } void out(long long *s, int n) { for (int i = 0; i <= n; i++) printf(i < n ? "%2lld " : "%2lld\n", s[i]); } void out(bool *s, int n) { for (int i = 0; i <= n; i++) printf(i < n ? "%2d " : "%2d\n", s[i] ? 1 : 0); } void out(int n) { for (int i = 0; i <= n; i++) printf(i < n ? "%2d " : "%2d\n", i); } }; // namespace Debug using namespace Math; using namespace Debug; const int maxn = 5500; struct Poi { int x, y, z; void init() { scanf("%d %d %d", &x, &y, &z); } } arr[maxn]; double dis(Poi a, Poi b) { double x = a.x - b.x; double y = a.y - b.y; double z = a.z - b.z; double di = x * x + y * y + z * z; return sqrt(di); } double cals(int p, int q) { double dp = dis(arr[1], arr[p]); double dq = dis(arr[1], arr[q]); double dpq = dis(arr[p], arr[q]); return 0.5 * (dp + dq + dpq); } int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) arr[i].init(); double ans = INF; for (int i = 2; i <= n; i++) { for (int j = i + 1; j <= n; j++) ans = ((ans) < (cals(i, j)) ? (ans) : (cals(i, j))); } printf("%.10f\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; double dist(vector<int> a, vector<int> b) { return sqrt(pow((double)a[0] - b[0], 2) + pow((double)a[1] - b[1], 2) + pow((double)a[2] - b[2], 2)); } int main() { int n; cin >> n; vector<vector<int> > v(n, vector<int>(3)); for (int i = 0; i < n; i++) cin >> v[i][0] >> v[i][1] >> v[i][2]; vector<double> d; for (int i = 0; i < n; i++) d.push_back(dist(v[0], v[i])); double ans = 1e100; for (int i = 1; i < n; i++) for (int j = i + 1; j < n; j++) if (d[i] + d[j] <= ans) ans = min(ans, d[i] + dist(v[i], v[j]) + d[j]); cout.precision(20); cout << ans / 2 << endl; }
#include <bits/stdc++.h> using namespace std; struct rmq { int r[8192 * 2 + 10]; double x[8192 * 2 + 10]; int y[8192 * 2 + 10]; void stab(int i) { if (x[i * 2] < x[i * 2 + 1]) { r[i] = r[i * 2]; x[i] = x[i * 2]; y[i] = y[i * 2]; } else { r[i] = r[i * 2 + 1]; x[i] = x[i * 2 + 1]; y[i] = y[i * 2 + 1]; } } void init() { for (int i = 8192; i < 8192 * 2; i++) { r[i] = i - 8192; x[i] = 1000000.0L; } for (int i = 8192 - 1; i >= 1; i--) { stab(i); } } void insert(int d, double l, int f) { if (x[8192 + d] > l) { x[8192 + d] = l; y[8192 + d] = f; d = (8192 + d) / 2; while (d >= 1) { stab(d); d /= 2; } } } void get_min(int &d, double &l, int &f) { d = r[1]; l = x[1]; f = y[1]; x[8192 + d] = 1000000.0L; int i = (8192 + d) / 2; while (i >= 1) { stab(i); i /= 2; } } }; rmq s; struct dot { double x, y, z; }; double length(dot a, dot b) { return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y) + (a.z - b.z) * (a.z - b.z)); } int n; dot a[5010]; double len[5010][5010]; int p[5010]; double w[5010]; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { p[i] = -1; scanf("%lf %lf %lf", &a[i].x, &a[i].y, &a[i].z); } for (int i = 0; i < n; i++) { for (int j = i; j < n; j++) { len[i][j] = len[j][i] = length(a[i], a[j]); } } p[0] = 0; w[0] = 0; for (int i = 1; i < n; i++) { w[i] = len[0][i]; p[i] = 0; } double ans = 0; bool f = false; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (p[i] != j && p[j] != i) { int x = i; int y = j; if (w[x] > w[y]) { swap(x, y); } if (w[x] + len[x][y] > w[y]) { if (f) { ans = min(ans, w[x] + fabs(w[y] - w[x]) + (len[x][y] - fabs(w[y] - w[x])) / 2); } else { ans = w[x] + fabs(w[y] - w[x]) + (len[x][y] - fabs(w[y] - w[x])) / 2; f = true; } } } } } printf("%.8lf\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; int n, m; double x[5005], y[5005], z[5005]; double cal(int i, int j) { double d1 = sqrt(pow(x[i] - x[0], 2) + pow(y[i] - y[0], 2) + pow(z[i] - z[0], 2)); d1 += sqrt(pow(x[j] - x[0], 2) + pow(y[j] - y[0], 2) + pow(z[j] - z[0], 2)); d1 += sqrt(pow(x[i] - x[j], 2) + pow(y[i] - y[j], 2) + pow(z[i] - z[j], 2)); return d1; } int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { cin >> x[i] >> y[i] >> z[i]; } double ans = -1; for (int i = 1; i < n; i++) for (int j = i + 1; j < n; j++) { if (ans == -1) { ans = cal(i, j); } else { ans = min(ans, cal(i, j)); } } printf("%.10f\n", ans / 2); return 0; }
#include <bits/stdc++.h> int main(void) { int n, x[5000], y[5000], z[5000], i, j; double ans = 1e100; scanf("%d\n", &n); for (i = 0; i < n; i++) { scanf("%d %d %d\n", &x[i], &y[i], &z[i]); } for (i = 1; i < n; i++) for (j = i + 1; j < n; j++) { double t = ((sqrt((x[0] - x[i]) * (x[0] - x[i]) + (y[0] - y[i]) * (y[0] - y[i]) + (z[0] - z[i]) * (z[0] - z[i]))) + (sqrt((x[0] - x[j]) * (x[0] - x[j]) + (y[0] - y[j]) * (y[0] - y[j]) + (z[0] - z[j]) * (z[0] - z[j]))) + (sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]) + (z[i] - z[j]) * (z[i] - z[j])))) / 2; if (t < ans) ans = t; } printf("%.7f\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; int n; double x[5000], y[5000], z[5000]; double ans; double dist(double x1, double y1, double z1, double x2, double y2, double z2) { return sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1) + (z2 - z1) * (z2 - z1)); } int main() { cin >> n; for (int i = 0; i < n; i++) cin >> x[i] >> y[i] >> z[i]; ans = (dist(x[0], y[0], z[0], x[1], y[1], z[1]) + dist(x[0], y[0], z[0], x[2], y[2], z[2]) + dist(x[1], y[1], z[1], x[2], y[2], z[2])) / 2; for (int i = 1; i < n; i++) for (int j = i + 1; j < n; j++) ans = min(ans, (dist(x[0], y[0], z[0], x[i], y[i], z[i]) + dist(x[0], y[0], z[0], x[j], y[j], z[j]) + dist(x[i], y[i], z[i], x[j], y[j], z[j])) / 2); cout.precision(9); cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; const int P = 1e9 + 7; int add(int a, int b) { if ((a += b) >= P) a -= P; return a; } int sub(int a, int b) { if ((a -= b) < 0) a += P; return a; } int mul(int a, int b) { return 1ll * a * b % P; } int kpow(int a, int b) { int r = 1; for (; b; b >>= 1, a = mul(a, a)) { if (b & 1) r = mul(r, a); } return r; } const int N = 5e3 + 7; int n, x[N], y[N], z[N]; double ans; double sqr(double x) { return x * x; } double dis(int i, int j) { return sqrt(sqr(x[i] - x[j]) + sqr(y[i] - y[j]) + sqr(z[i] - z[j])); } int main() { std::ios::sync_with_stdio(false); std::cin.tie(0); cout << setiosflags(ios::fixed); cout << setprecision(9); cin >> n; for (int i = (1); i < (n + 1); i++) cin >> x[i] >> y[i] >> z[i]; ans = (1ll << (60)); for (int i = (2); i < (n + 1); i++) for (int j = (i + 1); j < (n + 1); j++) { ans = min(ans, (dis(i, j) + dis(1, i) + dis(1, j)) / 2); } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; double ans = 10000000000000; struct node { int x, y, z; }; node q[5000 + 10]; int main() { int n; cin >> n; int i, j; for (i = 1; i <= n; i++) { int a, b, c; cin >> a >> b >> c; q[i].x = a; q[i].y = b; q[i].z = c; } for (i = 2; i <= n; i++) { for (j = i + 1; j <= n; j++) { if (i == j) continue; double t = sqrt((q[i].x - q[1].x) * (q[i].x - q[1].x) + (q[i].y - q[1].y) * (q[i].y - q[1].y) + (q[i].z - q[1].z) * (q[i].z - q[1].z)) + sqrt((q[j].x - q[1].x) * (q[j].x - q[1].x) + (q[j].y - q[1].y) * (q[j].y - q[1].y) + (q[j].z - q[1].z) * (q[j].z - q[1].z)) + sqrt((q[i].x - q[j].x) * (q[i].x - q[j].x) + (q[i].y - q[j].y) * (q[i].y - q[j].y) + (q[i].z - q[j].z) * (q[i].z - q[j].z)); if (t * 0.5 < ans) ans = t * 0.5; } } printf("%.12lf\n", ans); return 0; }
/* 2013-08-11 09:12:04.984985 */#include<iostream> #include<cstdio> #include<cstdlib> #include<ctime> #include<cmath> #include<cctype> #include<cstring> #include<algorithm> #include<map> #include<set> #include<vector> #include<string> #include<queue> #define Rep(i, a, b) for (int i(a); i <= (b); ++i) using namespace std; typedef long long LL; const int MAXN = 5023; int N, X[MAXN], Y[MAXN], Z[MAXN]; inline double dist(int i, int j) { LL a = X[i] - X[j]; a = a * a; LL b = Y[i] - Y[j]; b = b * b; LL c = Z[i] - Z[j]; c = c * c; return sqrt(a + b + c); } int main() { scanf("%d", &N); Rep(i, 1, N) { scanf("%d %d %d", X + i, Y + i, Z + i); } double ans = 1e100; Rep(i, 2, N) Rep(j, i + 1, N) { ans = min(ans, dist(i, j) + dist(1, i) + dist(1, j)); } printf("%.8f\n", ans * 0.5); return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 5000; int x[N], y[N], z[N]; inline double dist(int i, int j) { return sqrt(((x[i] - x[j]) * (x[i] - x[j])) + ((y[i] - y[j]) * (y[i] - y[j])) + ((z[i] - z[j]) * (z[i] - z[j]))); } int main() { int n; scanf("%d", &n); double ans = 1e20; for (int i = 0; i < (int)n; ++i) scanf("%d%d%d", &x[i], &y[i], &z[i]); for (int i = 0; i < (int)n; ++i) for (int j = 1; j < i; ++j) ans = min(ans, (dist(0, i) + dist(0, j) + dist(i, j)) / 2.); printf("%.20lf\n", (double)ans); return 0; }
#include <bits/stdc++.h> using namespace std; int x[5555], y[5555], z[5555]; double Dis[5555]; int sqr(int x) { return x * x; } double dis(int a, int b) { return sqrt(sqr(x[a] - x[b]) + sqr(y[a] - y[b]) + sqr(z[a] - z[b]) + 0.0); } int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d%d%d", &x[i], &y[i], &z[i]); Dis[i] = dis(0, i); } double ans = 1e20; for (int i = 1; i < n; i++) { for (int j = i + 1; j < n; j++) { ans = min(ans, Dis[i] + Dis[j] + dis(i, j)); } } printf("%.10lf\n", ans / 2); return 0; }
#include <bits/stdc++.h> using namespace std; struct p { int x, y, z; }; double dist(p a, p b) { return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y) + (a.z - b.z) * (a.z - b.z)); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<p> a(n); double ans = INT_MAX; for (int i = 0; i < n; ++i) cin >> a[i].x >> a[i].y >> a[i].z; for (int i = 1; i < n; ++i) { for (int j = 1; j < n; ++j) { if (i == j) continue; double d = (dist(a[i], a[0]) + dist(a[j], a[0]) + dist(a[i], a[j])) / 2; if (ans - d > 1e-8) ans = d; } } cout << setprecision(20) << ans; }
#include <bits/stdc++.h> using namespace std; const int maxn = 5005; struct point { double x, y, z; }; double dist(point p1, point p2) { return sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y) + (p1.z - p2.z) * (p1.z - p2.z)); } point arr[maxn]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) cin >> arr[i].x >> arr[i].y >> arr[i].z; double ans = 1e50; for (int i = 1; i < n; i++) for (int j = i + 1; j < n; j++) ans = min(ans, (dist(arr[0], arr[i]) + dist(arr[0], arr[j]) + dist(arr[i], arr[j])) / 2.0); printf("%.10lf\n", ans); return 0; }
#include <bits/stdc++.h> int n, x[5010], y[5010], z[5010]; inline double dist(int i, int j) { return sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]) + (z[i] - z[j]) * (z[i] - z[j])); } int main() { scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d%d%d", &x[i], &y[i], &z[i]); double ans = 2147483647; for (int i = 1; i < n - 1; i++) for (int j = i + 1; j < n; j++) { double d1 = dist(i, 0), d2 = dist(j, 0), d3 = dist(i, j); if (d1 > d2) std::swap(d1, d2); d3 -= d2 - d1; if (d3 >= 0) ans = std::min(ans, d2 + d3 / 2); } printf("%.7lf", ans); }
#include <bits/stdc++.h> using namespace std; struct Point { double x, y, z; }; Point pt[5000]; int n; double getDist(Point &a, Point &b) { double gx = a.x - b.x; double gy = a.y - b.y; double gz = a.z - b.z; return sqrt(gx * gx + gy * gy + gz * gz); } int main(void) { int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%lf %lf %lf", &pt[i].x, &pt[i].y, &pt[i].z); double ans = 999999999; for (int i = 1; i < n; i++) { for (int j = i + 1; j < n; j++) { double s1 = getDist(pt[0], pt[i]); double s2 = getDist(pt[0], pt[j]); double dist = getDist(pt[i], pt[j]); if (s1 > s2) swap(s1, s2); if (s1 + dist < s2 || (abs((s1 + dist) - (s2)) < 1e-10)) s1 = s1 + dist * 2; if (s1 > s2) swap(s1, s2); double temp = s1 + (s2 - s1) + (dist - (s2 - s1)) / 2; ans = min(ans, temp); } } printf("%.10lf\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; vector<vector<int> > adj; double mat[5010][5010]; long long X[5010], Y[5010], Z[5010]; pair<int, int> ditra(int s) { priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > PQ; PQ.push(pair<int, int>(0, s)); while (!PQ.empty()) { pair<int, int> c = PQ.top(); } } double dist(int i, int j) { return sqrt((X[i] - X[j]) * (X[i] - X[j]) + (Y[i] - Y[j]) * (Y[i] - Y[j]) + (Z[i] - Z[j]) * (Z[i] - Z[j])); } int main(int argc, char *argv[]) { int N; cin >> N; for (int i = 0; i < N; ++i) cin >> X[i] >> Y[i] >> Z[i]; double mi = 1e10; for (int i = 1; i < N; ++i) for (int j = i + 1; j < N; ++j) { mi = min(mi, dist(0, i) + dist(0, j) + dist(i, j)); } printf("%0.10lf\n", mi / 2.0); return 0; }
#include <bits/stdc++.h> using namespace std; int n; double ans, dist[5001][5001], a[5001][3]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%lf%lf%lf", &a[i][0], &a[i][1], &a[i][2]); for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) dist[i][j] = sqrt((a[i][0] - a[j][0]) * (a[i][0] - a[j][0]) + (a[i][1] - a[j][1]) * (a[i][1] - a[j][1]) + (a[i][2] - a[j][2]) * (a[i][2] - a[j][2])); ans = 1e20; for (int i = 2; i <= n; i++) for (int j = i + 1; j <= n; j++) ans = min(ans, (dist[1][i] + dist[1][j] + dist[i][j]) / 2.0); printf("%.10lf\n", ans); }
#include <bits/stdc++.h> using namespace std; int X[5003], Y[5003], Z[5003]; double d[5003], res = 1e9, k; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d%d%d", X + i, Y + i, Z + i), d[i] = sqrt(((X[0] - X[i]) * (X[0] - X[i])) + ((Y[0] - Y[i]) * (Y[0] - Y[i])) + ((Z[0] - Z[i]) * (Z[0] - Z[i]))); for (int i = 1; i < n; i++) for (int j = i + 1; j < n; j++) if ((k = sqrt(((X[i] - X[j]) * (X[i] - X[j])) + ((Y[i] - Y[j]) * (Y[i] - Y[j])) + ((Z[i] - Z[j]) * (Z[i] - Z[j]))) + d[i] + d[j]) < res) res = k; printf("%.10lf\n", res / 2); return 0; }
#include <bits/stdc++.h> using namespace std; struct pt { pt(double _x = 0, double _y = 0, double _z = 0) : x(_x), y(_y), z(_z) {} double x, y, z; }; istream& operator>>(istream& is, pt& P) { return is >> P.x >> P.y >> P.z; } ostream& operator<<(ostream& os, const pt& P) { return os << P.x << ' ' << P.y << ' ' << P.z; } pt pos[5000 + 10]; int n; double dist(int i, int j) { pt A = pos[i], B = pos[j]; double dx = A.x - B.x; double dy = A.y - B.y; double dz = A.z - B.z; return sqrt(dx * dx + dy * dy + dz * dz); } bool solve(int tc) { scanf("%d", &n); for (int i = (0); i < (n); ++i) { int x, y, z; scanf("%d %d %d", &x, &y, &z); pos[i] = pt(x, y, z); } double best = 1e28; for (int i = (1); i < (n); ++i) for (int j = (1); j < (n); ++j) if (i != j) best = min(best, (dist(0, i) + dist(i, j) + dist(j, 0)) / 2); printf("%f\n", best); return true; } int main() { int n = 1; if (!n) cin >> n; for (int i = 0; i < n && solve(i); ++i) ; return 0; }
#include <bits/stdc++.h> struct node { int x, y, z; } q[10000]; double d[5000][5000]; int main() { int n, i, j; while (~scanf("%d", &n)) { double min_ = 0x3f3f3f3f; for (i = 1; i <= n; i++) { scanf("%d %d %d", &q[i].x, &q[i].y, &q[i].z); } for (i = 1; i <= n; i++) { for (j = 1 + i; j <= n; j++) { double h; h = sqrt((q[j].x - q[i].x) * (q[j].x - q[i].x) + (q[j].y - q[i].y) * (q[j].y - q[i].y) + (q[j].z - q[i].z) * (q[j].z - q[i].z)); d[i][j] = d[j][i] = h; } } for (i = 2; i <= n; i++) { for (j = 2; j <= n; j++) { if (i != j) { min_ = min_ < d[i][j] + d[1][i] + d[1][j] ? min_ : d[i][j] + d[1][i] + d[1][j]; } } } printf("%.7lf\n", min_ / 2.0); } }
#include <bits/stdc++.h> using namespace std; vector<int> x, y, z; inline int sqr(int x) { return x * x; } inline double dist(int i, int j) { return sqrt(sqr(x[i] - x[j]) + sqr(y[i] - y[j]) + sqr(z[i] - z[j])); } int main() { int n; cin >> n; x.resize(n), y.resize(n), z.resize(n); for (int i = 0; i < n; ++i) cin >> x[i] >> y[i] >> z[i]; double shortestTime = 1e9; for (int i = 1; i < n; ++i) { for (int j = i + 1; j < n; ++j) { double d = dist(0, i) + dist(i, j) + dist(j, 0); shortestTime = min(shortestTime, d / 2); } } cout << setprecision(10) << shortestTime << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int count[103]; int n, m; double x[5002]; double y[5002]; double z[5002]; double T[5002]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%lf%lf%lf", &x[i], &y[i], &z[i]); for (int i = 2; i <= n; i++) T[i] = sqrt((x[i] - x[1]) * (x[i] - x[1]) + (y[i] - y[1]) * (y[i] - y[1]) + (z[i] - z[1]) * (z[i] - z[1])); double opttime = 1e30; for (int i = 2; i <= n; i++) for (int j = i + 1; j <= n; j++) { double D = sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]) + (z[i] - z[j]) * (z[i] - z[j])); double t = D + T[i] + T[j]; t = t * 0.5; if (t > T[i] && t < T[i] + D && t > T[j] && t < T[j] + D) opttime = min(opttime, t); } printf("%1.10f\n", opttime); }
#include <bits/stdc++.h> int main() { int x[5000], y[5000], z[5000]; int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d%d%d", x + i, y + i, z + i); double minlife = 1e10; double prec = 1e-8; double life; for (int i = 1; i < n - 1; i++) for (int j = i + 1; j < n; j++) { life = sqrt((x[i] - x[0]) * (x[i] - x[0]) + (y[i] - y[0]) * (y[i] - y[0]) + (z[i] - z[0]) * (z[i] - z[0])); life += sqrt((x[j] - x[0]) * (x[j] - x[0]) + (y[j] - y[0]) * (y[j] - y[0]) + (z[j] - z[0]) * (z[j] - z[0])); life += sqrt((x[j] - x[i]) * (x[j] - x[i]) + (y[j] - y[i]) * (y[j] - y[i]) + (z[j] - z[i]) * (z[j] - z[i])); if (minlife + prec > life) minlife = life; } printf("%.8f\n", minlife / 2); return 0; }
#include <bits/stdc++.h> using namespace std; double dist[5000][5000]; int n; double x[10000], y[10000], z[10000]; int main() { ios_base::sync_with_stdio(0); cin >> n; for (int i = 0; i < n; i++) { cin >> x[i] >> y[i] >> z[i]; for (int j = 0; j < i; j++) { dist[i][j] = (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]) + (z[i] - z[j]) * (z[i] - z[j]); dist[i][j] = sqrt(dist[i][j]); dist[j][i] = dist[i][j]; } } double ans = 1e10; for (int i = 1; i < n; i++) { for (int j = i + 1; j < n; j++) { ans = min(ans, (dist[i][j] + dist[0][i] + dist[j][0]) / 2.0); } } printf("%.10f\n", ans); }
#include <bits/stdc++.h> using namespace std; int n, m; struct point { double x, y, z; } P[5200]; inline double sqr(double x) { return x * x; } inline double dist(point a, point b) { return sqrt(sqr(a.x - b.x) + sqr(a.y - b.y) + sqr(a.z - b.z)); } inline double len(point a, point b, point c) { return dist(a, b) + dist(a, c) + dist(b, c); } int main() { cin >> n; double ans = 1e100; for (int i = 0; i < n; i++) cin >> P[i].x >> P[i].y >> P[i].z; for (int i = 1; i < n; i++) for (int j = i + 1; j < n; j++) ans = min(ans, len(P[0], P[i], P[j])); cout.precision(11); cout << ans / 2 << endl; }
#include <bits/stdc++.h> using namespace std; struct Planet { int x, y, z; }; double dis(Planet& a, Planet& b) { return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y) + (a.z - b.z) * (a.z - b.z)); } int main() { int n; cin >> n; vector<Planet> p(n); for (int i = 0; i < n; ++i) { cin >> p[i].x >> p[i].y >> p[i].z; } double ans = 1e20; for (int i = 1; i < n; ++i) { for (int j = i + 1; j < n; ++j) { ans = min(ans, dis(p[0], p[i]) + dis(p[0], p[j]) + dis(p[i], p[j])); } } printf("%.7f\n", ans / 2); }
#include <bits/stdc++.h> using namespace std; template <class _T> inline _T sqr(const _T& x) { return x * x; } template <class _T> inline string tostr(const _T& a) { ostringstream os(""); os << a; return os.str(); } template <class _T> inline istream& operator<<(istream& is, const _T& a) { is.putback(a); return is; } const double PI = 3.1415926535897932384626433832795; const double EPS = 1e-11; double x[5100], y[5100], z[5100], d[5100]; int n, u[5100]; inline double dist(double x, double y, double z, double xx, double yy, double zz) { return sqrt((x - xx) * (x - xx) + (y - yy) * (y - yy) + (z - zz) * (z - zz)); } void dijkstra() { for (int i = 0; i < n; i++) d[i] = 1e20; d[0] = 0; memset((u), 0, sizeof(u)); for (int i = 0; i < n; i++) { int ind; double mn = 1e21; for (int j = 0; j < n; j++) if (!u[j] && d[j] < mn) { mn = d[j]; ind = j; } u[ind] = 1; for (int j = 0; j < n; j++) { d[j] = min(d[j], dist(x[ind], y[ind], z[ind], x[j], y[j], z[j]) + d[ind]); } } } int main() { cout << setiosflags(ios::fixed) << setprecision(10); cin >> n; for (int i = 0; i < n; i++) { scanf("%lf%lf%lf", &x[i], &y[i], &z[i]); } dijkstra(); double ans = 1e22; for (int i = 1; i < n; i++) for (int j = i + 1; j < n; j++) { ans = min(ans, d[i] + d[j] + dist(x[i], y[i], z[i], x[j], y[j], z[j])); } cout << ans / 2; return 0; }
/* 2013-08-11 09:36:45.833173 */#include <cstdio> #include <cstring> #include <iostream> #include <cmath> #include <algorithm> #define sqr(x) ((x)*(x)) using namespace std; struct data{ int x,y,z; long double dis; }A[5005]; long double ans; inline bool operator < (data a,data b){ return a.dis<b.dis; } int main(){ int n,m,i,j,k,l; scanf("%d",&n); ans=1000000000000000.00; for(i=1;i<=n;i++)scanf("%d%d%d",&A[i].x,&A[i].y,&A[i].z); for(i=2;i<=n;i++){ A[i].dis=sqrt((long double)sqr(A[i].x-A[1].x)+sqr(A[i].y-A[1].y)+sqr(A[i].z-A[1].z)); } sort(A+2,A+1+n); for(i=2;i<=n;i++) for(j=i+1;j<=n;j++){ long double d1=sqrt((long double)sqr(A[i].x-A[j].x)+sqr(A[i].y-A[j].y)+sqr(A[i].z-A[j].z)); ans=min(ans,d1+A[i].dis+A[j].dis); /* if(A[i].dis+d1+eps<A[j].dis){ }*/ } printf("%.7f\n",(double)ans/2); // cout<<fixed()<<setprecision(7)<<ans<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; vector<int> x, y, z; long double d(int i, int j) { return sqrt(((x[i] - x[j]) * (x[i] - x[j])) + ((y[i] - y[j]) * (y[i] - y[j])) + ((z[i] - z[j]) * (z[i] - z[j]))); } int main() { int n; cin >> n; long double ans = 1000000000.0; x.resize(n); y.resize(n); z.resize(n); for (int i = 0; i < (int)(n); i++) { cin >> x[i] >> y[i] >> z[i]; } for (int i = 1; i < n; i++) { for (int j = i + 1; j < n; j++) { ans = min(ans, (d(i, j) + d(i, 0) + d(j, 0)) / 2.0); } } cout.precision(11); cout << ans; }
#include <bits/stdc++.h> using namespace std; int eprintf(const char *format, ...) { return 0; } struct pt { float x, y, z; pt() { x = y = z = 0; } pt(float _x, float _y, float _z) : x(_x), y(_y), z(_z) {} }; inline float dist(pt a, pt b) { return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y) + (a.z - b.z) * (a.z - b.z)); } float d[5000][5000]; int main() { long long stime = clock(); int n; while (scanf("%d", &n) >= 1) { vector<pt> pts(n); for (int i = 0; i < n; i++) scanf("%f%f%f", &pts[i].x, &pts[i].y, &pts[i].z); float ans = 1e100; for (int a = 0; a < n; a++) for (int b = 0; b < n; b++) d[a][b] = dist(pts[a], pts[b]); for (int a = 1; a < n; a++) for (int b = a + 1; b < n; b++) { ans = min(ans, d[0][a] + d[a][b] + d[b][0]); } ans /= 2; printf("%.20f\n", ans); break; } eprintf("%I64d\n", clock() - stime); return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 5010; int n; double x[maxn], y[maxn], z[maxn]; double dis(int i, int j) { double xx = x[i] - x[j]; double yy = y[i] - y[j]; double zz = z[i] - z[j]; return sqrt(xx * xx + yy * yy + zz * zz); } int main() { cin >> n; for (int i = 0; i < n; i++) cin >> x[i] >> y[i] >> z[i]; double ans = 1e20; for (int i = 1; i < n; i++) for (int j = i + 1; j < n; j++) { ans = min(ans, (dis(i, 0) + dis(j, 0) + dis(i, j)) / 2); } cout << fixed << setprecision(7); cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int MOD = 998244353; const int MAX = 998244353; long long gcd(long long a, long long b) { if (b == 0) { return a; } return gcd(b, a % b); } long double dist(long double x1, long double y1, long double z1, long double x2, long double y2, long double z2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) + (z1 - z2) * (z1 - z2)); } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n; cin >> n; vector<int> ix(n), iy(n), iz(n); vector<long double> x(n), y(n), z(n); for (int i = 0; i < n; ++i) { cin >> ix[i] >> iy[i] >> iz[i]; x[i] = ix[i]; y[i] = iy[i]; z[i] = iz[i]; } long double ans = 0. + MAX; for (int i = 1; i < n; ++i) { for (int j = i + 1; j < n; ++j) { long double cd = dist(x[i], y[i], z[i], x[j], y[j], z[j]); cd += dist(x[0], y[0], z[0], x[j], y[j], z[j]); cd += dist(x[i], y[i], z[i], x[0], y[0], z[0]); cd /= 2; ans = min(ans, cd); } } cout << setprecision(10) << ans << "\n"; return 0; }
#include <bits/stdc++.h> struct case1 { double x, y, z; } p[5001] = {0, 0, 0}; int main() { long i, j, n; double t, ans = 1000000000; scanf("%ld", &n); for (i = 1; i <= n; i++) scanf("%lf%lf%lf", &p[i].x, &p[i].y, &p[i].z); for (i = 2; i < n; i++) for (j = i + 1; j <= n; j++) { t = sqrt(((p[j].x) - (p[i].x)) * ((p[j].x) - (p[i].x)) + ((p[j].y) - (p[i].y)) * ((p[j].y) - (p[i].y)) + ((p[j].z) - (p[i].z)) * ((p[j].z) - (p[i].z))) + sqrt(((p[1].x) - (p[i].x)) * ((p[1].x) - (p[i].x)) + ((p[1].y) - (p[i].y)) * ((p[1].y) - (p[i].y)) + ((p[1].z) - (p[i].z)) * ((p[1].z) - (p[i].z))) + sqrt(((p[j].x) - (p[1].x)) * ((p[j].x) - (p[1].x)) + ((p[j].y) - (p[1].y)) * ((p[j].y) - (p[1].y)) + ((p[j].z) - (p[1].z)) * ((p[j].z) - (p[1].z))); ans = ((ans) < (t / 2) ? (ans) : (t / 2)); } printf("%.10lf\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; double pf(double x1, double x2, double y1, double y2, double z1, double z2) { return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) + (z1 - z2) * (z1 - z2); } double x[5001], y[5001], z[5001], dis[5001], Min, d; int main() { int n, i, j, k; cin >> n; cin >> x[0] >> y[0] >> z[0]; for (i = 1; i < n; i++) { cin >> x[i] >> y[i] >> z[i]; dis[i] = sqrt(pf(x[0], x[i], y[0], y[i], z[0], z[i])); } Min = 2000000000; for (i = 1; i < n; i++) for (j = 1; j < n; j++) { if (i == j) continue; d = dis[i] + dis[j] + sqrt(pf(x[j], x[i], y[j], y[i], z[j], z[i])); if (Min > d) Min = d; } printf("%.8lf\n", Min / 2); }
#include <bits/stdc++.h> using namespace std; typedef struct { int x; int y; int z; } T1; T1 V[5010]; double D[5010][5010]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> V[i].x >> V[i].y >> V[i].z; for (int j = 0; j < i; j++) D[j][i] = D[i][j] = sqrt(double((V[i].x - V[j].x) * (V[i].x - V[j].x) + (V[i].y - V[j].y) * (V[i].y - V[j].y) + (V[i].z - V[j].z) * (V[i].z - V[j].z))); } double minP = D[0][1] + D[1][2] + D[2][0]; for (int i = 1; i < n - 1; i++) for (int j = i + 1; j < n; j++) minP = min(minP, D[0][i] + D[i][j] + D[j][0]); cout.precision(10); cout << minP / 2.0; return 0; }
#include <bits/stdc++.h> using namespace std; int n; double ans = 1e10; struct point { int a, b, c; void get() { scanf("%d%d%d", &a, &b, &c); } }; point p[5001]; double di(int i, int j) { return sqrt((p[i].a - p[j].a) * (p[i].a - p[j].a) + (p[i].b - p[j].b) * (p[i].b - p[j].b) + (p[i].c - p[j].c) * (p[i].c - p[j].c)); } int main() { scanf("%d", &n); for (int i = 0; i < n; i++) p[i].get(); for (int i = 1; i < n; i++) for (int j = i + 1; j < n; j++) ans = min(ans, di(i, j) + di(0, i) + di(0, j)); printf("%.12lf\n", ans / 2); return 0; }
#include <bits/stdc++.h> using namespace std; struct pt { long double x, y, z; pt() {} pt(long double _x, long double _y, long double _z) : x(_x), y(_y), z(_z) {} pt(const pt &P) : x(P.x), y(P.y), z(P.z) {} long double length() { return sqrtl(x * x + y * y + z * z); } }; pt operator+(const pt &A, const pt &B) { return pt(A.x + B.x, A.y + B.y, A.z + B.z); } pt operator-(const pt &A, const pt &B) { return pt(A.x - B.x, A.y - B.y, A.z - B.z); } pt P[6000]; int main() { int N; cin >> N; for (int i = 0; i < N; ++i) { cin >> P[i].x; cin >> P[i].y; cin >> P[i].z; } long double Min = 1e+100; for (int i = 1; i < N; ++i) { for (int j = i + 1; j < N; ++j) { long double T1, T2; T1 = (P[i] - P[0]).length(); T2 = (P[j] - P[0]).length(); long double minT = min(T1, T2); long double maxT = max(T1, T2); long double dT = maxT - minT; long double PiPjDist = (P[i] - P[j]).length(); PiPjDist -= dT; PiPjDist /= 2; long double Tn = maxT + PiPjDist; Min = min(Min, Tn); } } cout.precision(50); cout << Min << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int static_init = []() { ios_base::sync_with_stdio(false), cin.tie(0), cout << fixed; return 0; }(); constexpr int N = 5e3; int16_t x[N], y[N], z[N]; double Dist(int i, int j) { int dx = x[i] - x[j]; int dy = y[i] - y[j]; int dz = z[i] - z[j]; return sqrt(dx * dx + dy * dy + dz * dz); } int main() { int n; cin >> n; for (int i = 0; i < n; i++) cin >> x[i] >> y[i] >> z[i]; auto ans = numeric_limits<double>::infinity(); for (int i = 1; i < n; i++) { for (int j = i + 1; j < n; j++) { ans = min(ans, 0.5 * (Dist(0, i) + Dist(0, j) + Dist(i, j))); } } cout << setprecision(7) << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; double x[6000], y[6000], z[6000], ans, t; int n; double dis(int i, int j) { return sqrt(0.0 + (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]) + (z[i] - z[j]) * (z[i] - z[j])); } int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> x[i] >> y[i] >> z[i]; } ans = 1e100; for (int i = 2; i <= n; i++) for (int j = 2; j <= n && j != i; j++) { t = dis(1, i) + dis(1, j) + dis(i, j); if (t < ans) ans = t; } printf("%.10lf", ans / 2); }
#include <bits/stdc++.h> using namespace std; int n; double d[5001][5001]; double x[5001], y[5001], z[5001]; double dist(int a, int b) { return sqrt((x[a] - x[b]) * (x[a] - x[b]) + (y[a] - y[b]) * (y[a] - y[b]) + (z[a] - z[b]) * (z[a] - z[b])); } int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%lf %lf %lf", &x[i], &y[i], &z[i]); for (int i = 1; i <= n; i++) { d[i][i] = 0; for (int j = i + 1; j <= n; j++) { d[i][j] = dist(i, j); d[j][i] = d[i][j]; } } double MIN = 1000000000.000; for (int i = 2; i <= n; i++) for (int j = i + 1; j <= n; j++) if (d[1][i] + d[1][j] + d[i][j] + 1e-7 < MIN) MIN = d[1][i] + d[1][j] + d[i][j]; printf("%.7lf", MIN / 2); return 0; }
#include <bits/stdc++.h> using namespace std; int n, i, j, k, x, y, z; double answer, a[5001][4], b[5000], p = 10000000000.00, s; int main() { cin >> n; for (i = 0; i < n; i++) { cin >> a[i][0] >> a[i][1] >> a[i][2]; } x = a[0][0]; y = a[0][1]; z = a[0][2]; for (i = 0; i < n - 1; i++) { b[i] = sqrt((x - a[i + 1][0]) * (x - a[i + 1][0]) + (y - a[i + 1][1]) * (y - a[i + 1][1]) + (z - a[i + 1][2]) * (z - a[i + 1][2])); } for (i = 0; i < n - 1; i++) { for (j = 0; j < n - 1; j++) { if (j != i) { s = sqrt((a[j + 1][0] - a[i + 1][0]) * (a[j + 1][0] - a[i + 1][0]) + (a[j + 1][1] - a[i + 1][1]) * (a[j + 1][1] - a[i + 1][1]) + (a[j + 1][2] - a[i + 1][2]) * (a[j + 1][2] - a[i + 1][2])); p = min(p, s + b[i] + b[j]); } } } answer = p / 2; cout.precision(12); cout << answer; }
#include <bits/stdc++.h> struct point { long x; long y; long z; }; const long maxn = 5001; const double inf = 2000000000; const double eps = 1.0e-8; point a[maxn]; double nnew, min; long n, q, choice1, choice2; double d[maxn]; double sqr(double x) { return (x * x); } double dist(point a, point b) { return (pow(sqr(a.x - b.x) + sqr(a.y - b.y) + sqr(a.z - b.z), 0.5)); } int main() { scanf("%ld", &n); for (q = 1; q <= n; q++) scanf("%ld%ld%ld", &a[q].x, &a[q].y, &a[q].z); min = inf; for (long h = 2; h <= n; h++) d[h] = dist(a[1], a[h]); for (choice1 = 2; choice1 <= n; choice1++) for (choice2 = choice1 + 1; choice2 <= n; choice2++) { nnew = (d[choice1] + d[choice2] + dist(a[choice1], a[choice2])) / 2; if (min - nnew > eps) min = nnew; } printf("%0.8lf", min); }
#include <bits/stdc++.h> using namespace std; void solve(); int main() { ios::sync_with_stdio(0); solve(); return 0; } inline double sqr(double x) { return x * x; } inline double dist(double* a, double* b) { return sqrt(sqr(a[0] - b[0]) + sqr(a[1] - b[1]) + sqr(a[2] - b[2])); } double pts[5000][3]; double d[5000]; void solve() { int n; cin >> n; for (int i = 0; i < n; i++) for (int j = 0; j < 3; j++) cin >> pts[i][j]; for (int i = 0; i < n; i++) d[i] = dist(pts[0], pts[i]); double ans = 1.0E100; for (int i = 1; i < n; i++) { for (int j = i + 1; j < n; j++) { double p = d[i] + d[j] + dist(pts[i], pts[j]); ans = min(ans, p / 2); } } cout.precision(20); cout << ans << '\n'; }
#include <bits/stdc++.h> long n; long long x[5005] = {0}, y[5005] = {0}, z[5005] = {0}; long long a[5005][5005] = {0}; long long qrt(long long a) { return (a * a); } int main() { long i, j, k, p = 0; double ans = 0.0, s; scanf("%ld", &n); for (i = 1; i <= n; i++) scanf("%I64d%I64d%I64d", &x[i], &y[i], &z[i]); for (i = 1; i <= n; i++) for (j = i + 1; j <= n; j++) a[i][j] = qrt(x[i] - x[j]) + qrt(y[i] - y[j]) + qrt(z[i] - z[j]); for (i = 1 + 1; i <= n; i++) for (j = i + 1; j <= n; j++) { if (!p) { ans = (sqrt((double)a[1][i]) + sqrt((double)a[1][j]) + sqrt((double)a[i][j])) / 2.0; p = 1; } else { s = (sqrt((double)a[1][i]) + sqrt((double)a[1][j]) + sqrt((double)a[i][j])) / 2.0; if (ans > s) ans = s; } } printf("%.10lf", ans); return (0); }
#include <bits/stdc++.h> using namespace std; const int N = 5005; struct _edge { int x, y, z; } k[N]; int n; double ans, temp; double dis(int x, int y) { double ans = sqrt(((k[x].x - k[y].x) * (k[x].x - k[y].x)) + ((k[x].y - k[y].y) * (k[x].y - k[y].y)) + ((k[x].z - k[y].z) * (k[x].z - k[y].z))); return ans; } int main() { scanf("%d", &n); ans = 1e15; for (int i = 1; i <= n; i++) scanf("%d %d %d", &k[i].x, &k[i].y, &k[i].z); for (int i = 2; i <= n - 1; i++) for (int j = i + 1; j <= n; j++) { temp = dis(i, j) + dis(1, j) + dis(1, i); if (temp < ans) ans = temp; } printf("%.10lf\n", ans / 2); return 0; }
#include <bits/stdc++.h> using namespace std; int n; double x[5055], y[5055], z[5055]; double sqr(double x) { return x * x; } double d(int a, int b) { double res = sqr(x[a] - x[b]) + sqr(y[a] - y[b]) + sqr(z[a] - z[b]); return sqrt(res); } int main() { scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%lf%lf%lf", &x[i], &y[i], &z[i]); double ans = d(0, 1) + d(0, 2) + d(1, 2); for (int i = 1; i < n; i++) for (int j = i + 1; j < n; j++) ans = min(ans, d(0, i) + d(0, j) + d(i, j)); printf("%.10lf\n", ans / 2); return 0; }
#include <bits/stdc++.h> using namespace std; struct planetloc { int x, y, z; }; planetloc arr[5010]; double dist(planetloc a, planetloc b) { return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y) + (a.z - b.z) * (a.z - b.z)); } int main() { cout << fixed << setprecision(10) << endl; int n; cin >> n; for (int i = 0; i < n; i++) { cin >> arr[i].x >> arr[i].y >> arr[i].z; } double ans = INT_MAX; for (int i = 1; i < n; i++) { for (int j = i + 1; j < n; j++) { ans = min(ans, dist(arr[0], arr[i]) + dist(arr[0], arr[j]) + dist(arr[j], arr[i])); } } cout << ans / 2 << endl; }
/* 2013-08-11 09:17:07.794206 */#include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <cmath> #include <iostream> #include <algorithm> using namespace std; int n; double ans, dist[5001][5001], a[5001][3]; int main(){ // freopen("d.in", "r", stdin); scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%lf%lf%lf", &a[i][0], &a[i][1], &a[i][2]); for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) dist[i][j] = sqrt( (a[i][0] - a[j][0]) * (a[i][0] - a[j][0]) + (a[i][1] - a[j][1]) * (a[i][1] - a[j][1]) + (a[i][2] - a[j][2]) * (a[i][2] - a[j][2])); ans = 1e20; for (int i = 2; i <= n; i++) for (int j = i + 1; j <= n; j++) ans = min(ans, (dist[1][i] + dist[1][j] + dist[i][j])/2.0); printf("%.10lf\n", ans); }
#include <bits/stdc++.h> using namespace std; const int inf = 1000000000; double m = inf; int n, i, j, a[5001], b[5001], c[5001]; double d; int main() { cin >> n; for (i = 1; i <= n; i++) cin >> a[i] >> b[i] >> c[i]; for (i = 2; i <= n - 1; i++) for (j = i + 1; j <= n; j++) { d = sqrt((a[i] - a[j]) * (a[i] - a[j]) + (b[i] - b[j]) * (b[i] - b[j]) + (c[i] - c[j]) * (c[i] - c[j])); d += sqrt((a[i] - a[1]) * (a[i] - a[1]) + (b[i] - b[1]) * (b[i] - b[1]) + (c[i] - c[1]) * (c[i] - c[1])); d += sqrt((a[1] - a[j]) * (a[1] - a[j]) + (b[1] - b[j]) * (b[1] - b[j]) + (c[1] - c[j]) * (c[1] - c[j])); if (m > d) m = d; } printf("%5f", m / 2); return 0; }
#include <bits/stdc++.h> using namespace std; template <typename T> inline bool uax(T &x, T y) { return (y > x) ? x = y, true : false; } template <typename T> inline bool uin(T &x, T y) { return (y < x) ? x = y, true : false; } void err(__attribute__((unused)) istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " =: " << a << endl; err(++it, args...); } template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> &buf) { return os << "(" << buf.first << ": " << buf.second << ")"; } template <typename T> ostream &operator<<(ostream &os, vector<vector<T>> &A) { for (auto &B : A) os << '\n' << B; return os; } template <typename T> ostream &operator<<(ostream &os, vector<T> &A) { bool f = false; os << "{"; for (auto &e : A) { if (f) os << ", "; os << e; f = true; } return os << "}"; } template <typename T> ostream &operator<<(ostream &os, set<T> &A) { bool f = false; os << "{"; for (auto &e : A) { if (f) os << ", "; os << e; f = true; } return os << "}"; } template <typename T> ostream &operator<<(ostream &os, multiset<T> &A) { bool f = false; os << "{"; for (auto &e : A) { if (f) os << ", "; os << e; f = true; } return os << "}"; } template <typename K, typename V> ostream &operator<<(ostream &os, map<K, V> &A) { bool f = false; os << "{"; for (auto &e : A) { if (f) os << ", "; os << e; f = true; } return os << "}"; } template <typename T> void kek(T ans) { cout << ans << endl; exit(0); } int const MOD = 1000000007; long long const INF = 1e18; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<array<int, 3>> a(n); for (auto &[x, y, z] : a) cin >> x >> y >> z; auto dis = [&a](int i, int j) { double ret = 0; for (int k : {0, 1, 2}) ret += (a[i][k] - a[j][k]) * (a[i][k] - a[j][k]); return sqrt(ret); }; double ans = INF; for (int i = 1; i < n; ++i) { for (int j = i + 1; j < n; ++j) { uin(ans, dis(0, i) + dis(0, j) + dis(i, j)); } } ans /= 2; cout.precision(7); cout << fixed << ans << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; char buf[1 << 21], *p1 = buf, *p2 = buf, obuf[1 << 23], *O = obuf; inline int read() { int x = 0, sign = 0; char s = getchar(); while (!isdigit(s)) sign |= s == '-', s = getchar(); while (isdigit(s)) x = (x << 1) + (x << 3) + (s - '0'), s = getchar(); return sign ? -x : x; } void print(int x) { if (x > 9) print(x / 10); (*O++ = x % 10 + '0'); } const int N = 5e3 + 5; double x[N], y[N], z[N], p[N], ans = 1e9; double dis(double a, double b, double c) { return sqrt(a * a + b * b + c * c); } int n; int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> x[i] >> y[i] >> z[i], p[i] = dis(x[i] - x[1], y[i] - y[1], z[i] - z[1]); for (int j = 2; j < i; j++) { double d = dis(x[i] - x[j], y[i] - y[j], z[i] - z[j]); ans = min(ans, (p[i] + d + p[j]) / 2); } } printf("%.10lf", ans); return 0; }
#include <bits/stdc++.h> using namespace std; int a[5010][5]; double dis(int x, int y) { double ans = 0.0; for (int i = 0; i < 3; i++) { ans += 1.0 * (a[x][i] - a[y][i]) * (a[x][i] - a[y][i]); } return sqrt(ans); } double min(double x, double y) { if (x - y < 0.00000001) return x; return y; } int main() { int n; scanf("%d", &n); double ans = 1000000.0; for (int i = 0; i < n; i++) { for (int j = 0; j < 3; j++) scanf("%d", &a[i][j]); for (int k = 1; k < i; k++) { double d = dis(0, i) + dis(0, k) + dis(i, k); ans = min(ans, d); } } printf("%.10f\n", ans / 2); return 0; }
#include <bits/stdc++.h> using namespace std; struct point { double x, y, z; }; double dist(const point &a, const point &b) { return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y) + (a.z - b.z) * (a.z - b.z)); } point p[5001]; int main() { int n; cin >> n; for (int i = 0; i < n; ++i) cin >> p[i].x >> p[i].y >> p[i].z; cout.precision(9); cout.setf(ios::fixed); double ans = 1e9; for (int i = 1; i < n; ++i) for (int j = i + 1; j < n; ++j) ans = min(ans, (dist(p[0], p[i]) + dist(p[0], p[j]) + dist(p[i], p[j]))); cout << ans / 2.; return 0; }
#include <bits/stdc++.h> using namespace std; struct Point { double x, y, z; void in() { scanf("%lf %lf %lf", &x, &y, &z); } } p[5010]; double dis(Point a, Point b) { return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y) + (a.z - b.z) * (a.z - b.z)); } int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) p[i].in(); double ans = 1e20; for (int i = 1; i < n; i++) for (int j = i + 1; j < n; j++) ans = min(ans, dis(p[0], p[i]) + dis(p[0], p[j]) + dis(p[i], p[j])); printf("%.12f\n", ans * 0.5); return 0; }
#include <bits/stdc++.h> using namespace std; const long long N = 2e5 + 5; const long long mod = 1e9 + 7; struct pt { long long x, y, z; } a[5005]; long double dist(pt a, pt b) { return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y) + (a.z - b.z) * (a.z - b.z)); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n; cin >> n; for (long long i = 0; i < n; i++) cin >> a[i].x >> a[i].y >> a[i].z; long double ans = 1e18; for (long long i = 1; i < n; i++) { for (long long j = i + 1; j < n; j++) { long double val = dist(a[i], a[0]) + dist(a[i], a[j]) + dist(a[j], a[0]); ans = min(ans, val / 2); } } cout << fixed << setprecision(18) << ans; }
#include <bits/stdc++.h> struct node { double x, y, z; } p[5005]; double d[5005]; double getlen(node a, node b) { double len; len = (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y) + (a.z - b.z) * (a.z - b.z); return sqrt(len); } int main() { int n, i, j, a, b, c; while (scanf("%d", &n) != EOF) { for (i = 0; i < n; i++) { scanf("%d %d %d", &a, &b, &c); p[i].x = a * 1.0; p[i].y = b * 1.0; p[i].z = c * 1.0; } for (i = 1; i < n; i++) { d[i] = getlen(p[0], p[i]); } double lenn; double max = 9999999.0; for (i = 1; i < n; i++) { for (j = 1; j <= i; j++) { if (j == i) continue; lenn = d[i] + d[j] + getlen(p[i], p[j]); if (max - lenn > 1e-6) max = lenn; } } printf("%.10f\n", max * 1.0 / 2.0); } return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 5000; int x[N], y[N], z[N]; long double dist(int i, int j) { return sqrt(((x[i] - x[j]) * (x[i] - x[j])) + ((y[i] - y[j]) * (y[i] - y[j])) + ((z[i] - z[j]) * (z[i] - z[j]))); } int main() { int n; scanf("%d", &n); long double ans = 1e20; for (int i = 0; i < (int)n; ++i) scanf("%d%d%d", &x[i], &y[i], &z[i]); for (int i = 0; i < (int)n; ++i) for (int j = 0; j < (int)i; ++j) if (j != 0) ans = min(ans, (dist(0, i) + dist(0, j) + dist(i, j)) / 2.); printf("%.20lf\n", (double)ans); return 0; }
#include <bits/stdc++.h> using namespace std; const int inf = (int)1e9; const int mod = (int)1e9 + 7; const double pi = acos(-1.0); const double eps = 1e-9; struct Point { double x, y, z; Point() {} Point(double x, double y, double z) : x(x), y(y), z(z) {} void read() { scanf("%lf%lf%lf", &x, &y, &z); } double dist(Point o) { return sqrt(((o.x - x) * (o.x - x)) + ((o.y - y) * (o.y - y)) + ((o.z - z) * (o.z - z))); } } a[5 * 1005]; int n; double calc(Point a, Point b, Point c) { return a.dist(b) + a.dist(c) + b.dist(c); } int main() { scanf("%d", &n); for (int i = 0; i < n; i++) a[i].read(); double mn = inf * 1.0 * inf; for (int i = 1; i < n; i++) for (int j = i + 1; j < n; j++) mn = min(mn, calc(a[0], a[i], a[j])); printf("%.9lf\n", mn / 2.0); return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 5000 + 10; int n; double x[N], y[N], z[N], dis[N], ans = 2e9; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%lf%lf%lf", &x[i], &y[i], &z[i]); for (int i = 2; i <= n; i++) dis[i] = sqrt((x[1] - x[i]) * (x[1] - x[i]) + (y[1] - y[i]) * (y[1] - y[i]) + (z[1] - z[i]) * (z[1] - z[i])); for (int i = 2; i <= n; i++) for (int j = 2; j <= n; j++) if (i != j) ans = min(ans, dis[i] + (fabs(dis[i] - dis[j]) + sqrt((x[j] - x[i]) * (x[j] - x[i]) + (y[j] - y[i]) * (y[j] - y[i]) + (z[j] - z[i]) * (z[j] - z[i]))) / 2); printf("%.12lf\n", ans); }
#include <bits/stdc++.h> using namespace std; int sqr(int c) { return c * c; } struct plan { int x, y, z; }; int main() { int n; plan a[5002]; double r[5002] = {0}; scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d%d%d", &a[i].x, &a[i].y, &a[i].z); for (int i = 2; i <= n; i++) r[i] = sqrt(1.0 * sqr(a[1].x - a[i].x) + sqr(a[1].y - a[i].y) + sqr(a[1].z - a[i].z)); double minr = 2000000000; for (int i = 2; i <= n; i++) for (int j = 2; j <= n; j++) if (i != j) { double ra = sqrt(1.0 * sqr(a[j].x - a[i].x) + sqr(a[j].y - a[i].y) + sqr(a[j].z - a[i].z)); if ((ra + r[i] + r[j]) / 2 < minr) minr = (ra + r[i] + r[j]) / 2; } printf("%.10f", minr); return 0; }
#include <bits/stdc++.h> const long long md = 998244353; const int Inf = 1e9; const long long Inf64 = 1e18; const long long MaxN = 110; const long long LogN = 25; const long long MaxM = 5e5 + 10; const long double eps = 1e-7; const long long dx[4] = {0, 1, 0, -1}; const long long dy[4] = {1, 0, -1, 0}; const long long ddx[4] = {1, 1, -1, -1}; const long long ddy[4] = {1, -1, 1, -1}; const long double Pi = acos(-1); using namespace std; template <typename T> istream &operator>>(istream &in, pair<T, T> &a) { in >> a.first >> a.second; return in; } template <typename T> ostream &operator<<(ostream &out, pair<T, T> a) { out << a.first << ' ' << a.second; return out; } template <typename T> istream &operator>>(istream &in, vector<T> &Mt) { for (T &a : Mt) in >> a; return in; } template <typename T> ostream &operator<<(ostream &out, vector<T> Mt) { for (int i = 0; i < Mt.size(); i++) { out << Mt[i]; if (i != Mt.size()) out << ' '; } return out; } inline long long Mod(long long &a, long long m = md) { while (a > m) a -= m; return a; } inline long long gcd(long long a, long long b) { while (a) { b %= a; swap(a, b); } return b; } inline long long gcdex(long long a, long long mod = md) { long long g = mod, r = a, x = 0, y = 1; while (r != 0) { long long q = g / r; g %= r; swap(g, r); x -= q * y; swap(x, y); } return x < 0 ? x + mod : x; } inline long long binpow(long long a, long long n, long long m = md) { long long res = 1; while (n) { if (n & 1) { res *= a; res %= m; } a *= a; a %= m; n >>= 1; } return res % md; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << fixed, cout.precision(20); long long N; cin >> N; vector<pair<long long, pair<long long, long long> > > Mt(N); for (int i = 0; i < N; i++) { cin >> Mt[i].first >> Mt[i].second; } vector<long double> d(N); long double Ans = Inf; for (int i = 1; i < N; i++) { d[i] = sqrt((Mt[0].first - Mt[i].first) * (Mt[0].first - Mt[i].first) + (Mt[0].second.first - Mt[i].second.first) * (Mt[0].second.first - Mt[i].second.first) + (Mt[0].second.second - Mt[i].second.second) * (Mt[0].second.second - Mt[i].second.second)); for (int j = 1; j < i; j++) { Ans = min(Ans, d[i] + d[j] + sqrt((Mt[j].first - Mt[i].first) * (Mt[j].first - Mt[i].first) + (Mt[j].second.first - Mt[i].second.first) * (Mt[j].second.first - Mt[i].second.first) + (Mt[j].second.second - Mt[i].second.second) * (Mt[j].second.second - Mt[i].second.second))); } } cout << Ans / 2.; return 0; }
#include <bits/stdc++.h> using namespace std; int n; double t[5001]; double x[5001], y[5001], z[5001]; int main() { cin >> n; cin >> x[0] >> y[0] >> z[0]; double res = 1e9; for (int i = 1, _s = n; i < _s; ++i) { cin >> x[i] >> y[i] >> z[i]; t[i] = sqrt((x[i] - x[0]) * (x[i] - x[0]) + (y[i] - y[0]) * (y[i] - y[0]) + (z[i] - z[0]) * (z[i] - z[0])); for (int j = 1, _s = i; j < _s; ++j) { double d = sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]) + (z[i] - z[j]) * (z[i] - z[j])); double c = max(t[j], t[i]) + (d - fabs(t[i] - t[j])) / 2.0; res = min(res, c); } } printf("%.10lf\n", res); return 0; }
#include <bits/stdc++.h> using namespace std; int x[5000], y[5000], z[5000]; double dist[5000][5000]; inline double SQR(double a) { return a * a; } inline double SQR_DIST(int i, int j) { return SQR(x[i] - x[j]) + SQR(y[i] - y[j]) + SQR(z[i] - z[j]); } int main() { int n; cin >> n; for (int i = (int)(0); i < (int)(n); i++) cin >> x[i] >> y[i] >> z[i]; for (int i = (int)(0); i < (int)(n); i++) { dist[i][i] = 0.0; for (int j = (int)(0); j < (int)(i); j++) { dist[i][j] = dist[j][i] = sqrt(SQR_DIST(i, j)); } } priority_queue<pair<double, pair<int, int> >, vector<pair<double, pair<int, int> > >, greater<pair<double, pair<int, int> > > > que; que.push(make_pair(0.0, make_pair(-1, 0))); bool already[5000]; memset(already, 0, sizeof(already)); double arrivedTime[5000]; while (!que.empty()) { pair<double, pair<int, int> > now = que.top(); que.pop(); if (now.second.second == -1) { printf("%.10lf\n", now.first); break; } already[now.second.second] = true; arrivedTime[now.second.second] = now.first; double HitTime = -1; for (int i = (int)(0); i < (int)(n); i++) if (i != now.second.first && i != now.second.second) { if (already[i]) { double sub = now.first - arrivedTime[i]; double rem = dist[i][now.second.second] - sub; if (HitTime < -1.0e-10 || HitTime > 1.0e-10 && HitTime > rem / 2) HitTime = rem / 2; } else { que.push(make_pair(now.first + dist[now.second.second][i], make_pair(now.second.second, i))); } } if (HitTime > -1.0e-10) que.push(make_pair(HitTime + now.first, make_pair(-1, -1))); } return 0; }
#include <bits/stdc++.h> using namespace std; struct Point { double x, y, z; friend istream& operator>>(istream& is, Point& pt) { return is >> pt.x >> pt.y >> pt.z; } }; double bang(const Point& pa, const Point& pb) { double a = sqrt(pa.x * pa.x + pa.y * pa.y + pa.z * pa.z); double b = sqrt(pb.x * pb.x + pb.y * pb.y + pb.z * pb.z); double c = sqrt((pa.x - pb.x) * (pa.x - pb.x) + (pa.y - pb.y) * (pa.y - pb.y) + (pa.z - pb.z) * (pa.z - pb.z)); return (a + b + c) / 2; } int main() { int n; cin >> n; vector<Point> ps(n); for (int i = 0; i < n; ++i) { cin >> ps[i]; if (i) { ps[i].x -= ps[0].x; ps[i].y -= ps[0].y; ps[i].z -= ps[0].z; } } double t = 1e+300; for (int a = 1; a < n; ++a) for (int b = a + 1; b < n; ++b) t = min(t, bang(ps[a], ps[b])); cout << setiosflags(ios::fixed) << setprecision(10) << t << endl; }
#include <bits/stdc++.h> using namespace std; const int N = 5005; int n; double x[N], y[N], z[N]; double sqr(const double x) { return x * x; } double dist(const int i, const int j) { return sqrt(sqr(x[i] - x[j]) + sqr(y[i] - y[j]) + sqr(z[i] - z[j])); } int main() { int n; scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%lf%lf%lf", x + i, y + i, z + i); } double ans = 1e20; for (int i = 1; i < n; ++i) { for (int j = i + 1; j < n; ++j) { ans = min(ans, dist(i, j) + dist(0, i) + dist(0, j)); } } printf("%.12f\n", ans / 2); return 0; }
#include <bits/stdc++.h> using namespace std; long double sq(int v) { return (long double)(v * v); } struct t { int x, y, z; t(){}; t(int a, int b, int c) { x = a, y = b, z = c; } }; t v[5005]; int N; long double dist(int a, int b) { return sqrt(sq(v[a].x - v[b].x) + sq(v[a].y - v[b].y) + sq(v[a].z - v[b].z)); } int main() { cin >> N; for (int i = 0; i < N; i++) { int x, y, z; cin >> x >> y >> z; v[i] = t(x, y, z); } long double mm = 1000000000; for (int i = 1; i < N; i++) { for (int j = i + 1; j < N; j++) { long double d0i = dist(0, i); long double d0j = dist(0, j); long double dij = dist(i, j); mm = min(mm, dij + d0i + d0j); } } cout << fixed << setprecision(18) << mm / 2 << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9; const long long INF64 = 1e18; const long long MOD = 1e9 + 7; const long long MOD9 = 1e9 + 9; const long long MOD3 = 998244353; const long long P = 37; const long long mxn = 1000; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count()); signed main() { ios_base::sync_with_stdio(0); cin.tie(0); long long n; cin >> n; vector<tuple<long long, long long, long long>> a(n); for (long long i = 0; i < n; ++i) { long long x, y, z; cin >> x >> y >> z; a[i] = make_tuple(x, y, z); } long long x0, y0, z0; x0 = get<0>(a[0]); y0 = get<1>(a[0]); z0 = get<2>(a[0]); long double answ = 9999999999.0; for (long long j = 1; j < n; ++j) { for (long long i = j + 1; i < n; ++i) { long long x, y, z, x2, y2, z2; x = get<0>(a[i]); y = get<1>(a[i]); z = get<2>(a[i]); x2 = get<0>(a[j]); y2 = get<1>(a[j]); z2 = get<2>(a[j]); long double d = sqrt((x - x2) * (x - x2) + (y - y2) * (y - y2) + (z - z2) * (z - z2)) + sqrt((x0 - x2) * (x0 - x2) + (y0 - y2) * (y0 - y2) + (z0 - z2) * (z0 - z2)) + sqrt((x - x0) * (x - x0) + (y - y0) * (y - y0) + (z - z0) * (z - z0)); answ = min(d, answ); } } cout.precision(10); cout << fixed << answ / 2.0; }
#include <bits/stdc++.h> using namespace std; struct node { double a, b, c; }; node mm[5005]; double len(node a, node b) { return sqrt((a.a - b.a) * (a.a - b.a) + (a.b - b.b) * (a.b - b.b) + (a.c - b.c) * (a.c - b.c)); } double cal(int a, int b) { double sum = 0; sum = len(mm[0], mm[a]); sum += len(mm[0], mm[b]); sum += len(mm[a], mm[b]); return sum; } int main() { int n, i, j, k; while (scanf("%d", &n) != EOF) { for (i = 0; i < n; i++) { scanf("%lf%lf%lf", &mm[i].a, &mm[i].b, &mm[i].c); } double sum, mmin; mmin = 99999999; for (j = 1; j < n; j++) { for (k = j + 1; k < n; k++) { sum = cal(j, k); if (sum < mmin) mmin = sum; } } printf("%lf\n", mmin / 2); } return 0; }
#include <bits/stdc++.h> using namespace std; int n; double x[5000 + 1], y[5000 + 1], z[5000 + 1]; vector<pair<double, int> > ds; double cal(double x1, double y1, double z1, double x2, double y2, double z2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) + (z1 - z2) * (z1 - z2)); } int input(void) { double dis, tmp; scanf("%d", &n); for (register int i = 1; i <= n; i++) { scanf("%lf%lf%lf", x + i, y + i, z + i); ds.push_back(pair<double, int>(cal(x[1], y[1], z[1], x[i], y[i], z[i]), i)); } sort(ds.begin(), ds.end()); int a = ds[1].second, b = ds[2].second; dis = ds[1].first + ds[2].first + cal(x[a], y[a], z[a], x[b], y[b], z[b]); for (register int i = 3; i <= n - 1; i++) { a = ds[i].second; for (register int j = 1; j <= i - 1; j++) { b = ds[j].second; tmp = ds[i].first + ds[j].first; if (tmp > dis) break; tmp += cal(x[a], y[a], z[a], x[b], y[b], z[b]); dis = min(dis, tmp); } } printf("%lf\n", dis / 2); return 0; } int main(void) { input(); return 0; }
#include <bits/stdc++.h> using namespace std; const int inf = 1 << 29; const double dinf = 1e30; const long long linf = 1LL << 55; const int N = 5555; int n; struct Point { int x, y, z; void read() { cin >> x >> y >> z; } } p[N]; double getDist(const Point &a, const Point &b) { return sqrt((1.0 * a.x - b.x) * (a.x - b.x) + (1.0 * a.y - b.y) * (a.y - b.y) + (1.0 * a.z - b.z) * (a.z - b.z)); } int main() { while (cin >> n) { for (int i = 0; i < n; i++) p[i].read(); double ans = dinf; for (int i = 1; i < n; i++) { for (int j = i + 1; j < n; j++) { double tmp = getDist(p[0], p[i]) + getDist(p[0], p[j]) + getDist(p[i], p[j]); ans = min(ans, tmp / 2.0); } } printf("%.10f\n", ans); } return 0; }
#include <bits/stdc++.h> using namespace std; int n; int x[5000], y[5000], z[5000]; double sol = 1e20; inline double dist(int i, int j) { int q = x[i] - x[j]; int w = y[i] - y[j]; int e = z[i] - z[j]; return (double)sqrt(double(q * q + w * w + e * e)); } int main() { scanf("%d", &n); for (int i = 0; i < n; ++i) scanf("%d %d %d", x + i, y + i, z + i); for (int i = 1; i < n - 1; ++i) for (int j = i + 1; j < n; ++j) sol = min(sol, dist(0, i) + dist(0, j) + dist(i, j)); printf("%.10lf\n", sol / 2.); return 0; }
#include <bits/stdc++.h> using namespace std; int x[5100], y[5100], z[5100]; double dis(int i, int j) { int dx = x[i] - x[j], dy = y[i] - y[j], dz = z[i] - z[j]; return sqrt(dx * dx + dy * dy + dz * dz + 0.0); } int main() { int n; cin >> n; for (int i = 1; i <= n; ++i) scanf("%d %d %d", &x[i], &y[i], &z[i]); double res = dis(1, 2) + dis(2, 3) + dis(3, 1); for (int i = 2; i < n; ++i) for (int j = i + 1; j <= n; ++j) res = min(res, dis(1, i) + dis(i, j) + dis(j, 1)); printf("%.10lf\n", res / 2.0); return 0; }
#include <bits/stdc++.h> using namespace std; typedef struct { int x; int y; int z; } T1; T1 V[5010]; double D[5010][5010]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> V[i].x >> V[i].y >> V[i].z; for (int j = 0; j < i; j++) D[j][i] = D[i][j] = sqrt(double((V[i].x - V[j].x) * (V[i].x - V[j].x) + (V[i].y - V[j].y) * (V[i].y - V[j].y) + (V[i].z - V[j].z) * (V[i].z - V[j].z))); } double minP = D[0][1] + D[1][2] + D[2][0]; for (int i = 1; i < n - 1; i++) for (int j = i + 1; j < n; j++) minP = min(minP, D[0][i] + D[i][j] + D[j][0]); cout.precision(10); cout << minP / 2.0; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 5000; int n; struct Point { int x, y, z; Point(int x = 0, int y = 0, int z = 0) { this->x = x; this->y = y; this->z = z; } }; Point a[N]; double rast(Point a, Point b) { double dx = a.x - b.x; double dy = a.y - b.y; double dz = a.z - b.z; return sqrt(dx * dx + dy * dy + dz * dz); } int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { int x, y, z; scanf("%d%d%d", &x, &y, &z); a[i] = Point(x, y, z); } double res = 1e30; for (int i = 1; i < n; i++) for (int j = i + 1; j < n; j++) res = min(res, (rast(a[0], a[i]) + rast(a[0], a[j]) + rast(a[i], a[j])) / 2); printf("%.10lf", res); return 0; }
#include <bits/stdc++.h> using namespace std; vector<int> v; int n; const int N = 5000; struct coord { int x; int y; int z; }; int x[N]; int y[N]; int z[N]; coord crd[N]; istream& operator>>(istream& cin, coord& c) { return cin >> c.x >> c.y >> c.z; } double r(coord c1, coord c2) { double dx = abs(c1.x - c2.x); double dy = abs(c1.y - c2.y); double dz = abs(c1.z - c2.z); return sqrt(dx * dx + dy * dy + dz * dz); } int main() { if (0) freopen("input.txt", "r", stdin); cin >> n; coord home; cin >> home; for (int i = 0; i < n - 1; i++) { cin >> crd[i]; } double minper = 999999999999; for (int i = 0; i < n - 1; i++) { for (int j = i + 1; j < n - 1; j++) { double per = r(home, crd[i]) + r(crd[j], crd[i]) + r(home, crd[j]); if (0) cout << i << " " << j << endl; if (0) cout << r(home, crd[i]) << endl; if (0) cout << r(home, crd[j]) << endl; if (0) cout << r(crd[j], crd[i]) << endl; if (0) cout << endl; minper = min(per, minper); } } cout << fixed << std::setprecision(10) << minper / 2; return 0; }
#include <bits/stdc++.h> using namespace std; double x[(10000)], y[(10000)], z[(10000)], t[(10000)]; double ans; int n; const double inf = 1e10; double dist(int a, int b) { return sqrt(((x[a] - x[b]) * (x[a] - x[b])) + ((y[a] - y[b]) * (y[a] - y[b])) + ((z[a] - z[b]) * (z[a] - z[b]))); } void work() { for (int i = 1; i <= n; i++) scanf("%lf%lf%lf", &x[i], &y[i], &z[i]); for (int i = 2; i <= n; i++) t[i] = dist(1, i); t[1] = 0; ans = inf; for (int i = 2; i <= n; i++) for (int j = 2; j < i; j++) ans = min(ans, max(t[i], t[j]) + (-fabs(t[i] - t[j]) + dist(i, j)) / 2.0); printf("%.10lf\n", ans); } int main() { for (; scanf("%d", &n) == 1 && n; work()) ; return 0; }
#include <bits/stdc++.h> using namespace std; int x[5000], y[5000], z[5000]; double ro(int i, int j) { double ans = (x[i] - x[j]) * (x[i] - x[j]); ans += (y[i] - y[j]) * (y[i] - y[j]); ans += (z[i] - z[j]) * (z[i] - z[j]); ans = sqrt(ans); return ans; } int main() { int n; cin >> n; double minnn = 1000000000; for (int i = 0; i < n; i++) cin >> x[i] >> y[i] >> z[i]; for (int i = 1; i < n - 1; i++) for (int j = i + 1; j < n; j++) { double ans = ro(0, j) + ro(0, i) + ro(i, j); ans /= 2.0; if (ans < minnn) minnn = ans; } cout.precision(12); cout << minnn; return 0; }
#include <bits/stdc++.h> using namespace std; long double x[1000000], y[1000000], z[1000000]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) cin >> x[i] >> y[i] >> z[i]; long double mini = 2000000000; for (int i = 1; i < n; i++) { for (int j = i + 1; j < n; j++) { long double hi1 = ((x[i] - x[0]) * (x[i] - x[0])) + ((y[i] - y[0]) * (y[i] - y[0])) + ((z[i] - z[0]) * (z[i] - z[0])); long double hi2 = ((x[j] - x[0]) * (x[j] - x[0])) + ((y[j] - y[0]) * (y[j] - y[0])) + ((z[j] - z[0]) * (z[j] - z[0])); hi1 = sqrt(hi1); hi2 = sqrt(hi2); hi1 += hi2; long double u = ((x[i] - x[j]) * (x[i] - x[j])) + ((y[i] - y[j]) * (y[i] - y[j])) + ((z[i] - z[j]) * (z[i] - z[j])); u = sqrt(u); hi1 += u; hi1 /= 2; mini = min(mini, hi1); } } cout << fixed << setprecision(20) << mini; return 0; }
#include <bits/stdc++.h> using namespace std; struct Point { int x, y, z; Point() : x(), y(), z() {} Point(int _x, int _y, int _z) : x(_x), y(_y), z(_z) {} Point operator-(const Point &A) const { return Point(x - A.x, y - A.y, z - A.z); } double len() { return sqrt((double)x * x + y * y + z * z); } void read() { scanf("%d%d%d", &x, &y, &z); } }; const int N = (int)1e5 + 100; Point P[N]; int main(int, char **) { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { P[i].read(); } double ans = 1e9; for (int a = 1; a < n; a++) for (int b = a + 1; b < n; b++) { double sum = (P[a] - P[0]).len() + (P[b] - P[0]).len() + (P[b] - P[a]).len(); ans = min(ans, sum / 2); } printf("%.10lf\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; double x[7000], y[7000], z[7000], mm = 99999999; int n, i, j, k; double d(int u, int v) { double p; p = sqrt(((x[u] - x[v]) * (x[u] - x[v])) + ((y[u] - y[v]) * (y[u] - y[v])) + ((z[u] - z[v]) * (z[u] - z[v]))); return p; } int main() { cin >> n; for (i = 1; i < n + 1; i++) { cin >> x[i] >> y[i] >> z[i]; } double tt = 0; for (i = 2; i < n; i++) for (j = i + 1; j < n + 1; j++) { tt = d(i, j) + d(1, j) + d(1, i); mm = min(mm, tt); } printf("%.6f", mm / 2); }
#include <bits/stdc++.h> using namespace std; double d(int x1, int y1, int z1, int x2, int y2, int z2) { int dx = x2 - x1, dy = y2 - y1, dz = z2 - z1; return sqrt(dx * dx + dy * dy + dz * dz); } int main() { int n; cin >> n; int x[n], y[n], z[n]; double dist[n]; for (int i = 0; i < n; i++) { cin >> x[i] >> y[i] >> z[i]; dist[i] = d(x[i], y[i], z[i], x[0], y[0], z[0]); } double ans = 1e9; for (int i = 1; i < n; i++) for (int j = i + 1; j < n; j++) ans = min(ans, dist[i] + dist[j] + d(x[i], y[i], z[i], x[j], y[j], z[j])); printf("%.10f\n", ans / 2); }
#include <bits/stdc++.h> using namespace std; double dist(int a, int b, int c, int d, int e, int first) { return sqrt((a - d) * (a - d) + (b - e) * (b - e) + (c - first) * (c - first)); } int main() { ios_base::sync_with_stdio(0); int n, m; cin >> n; int a[n][3]; double ans = 2147483647; for (int i = 0; i < n; ++i) cin >> a[i][0] >> a[i][1] >> a[i][2]; for (int i = 1; i < n; ++i) for (int j = i + 1; j < n; ++j) ans = min(ans, dist(a[0][0], a[0][1], a[0][2], a[i][0], a[i][1], a[i][2]) + dist(a[0][0], a[0][1], a[0][2], a[j][0], a[j][1], a[j][2]) + dist(a[i][0], a[i][1], a[i][2], a[j][0], a[j][1], a[j][2])); printf("%.9f\n", ans / 2.0); return 0; }
#include <bits/stdc++.h> using namespace std; double n, arr[6000][4] = {0}, a, b, c; int main() { cin >> n; cin >> a >> b >> c; for (int i = 0; i < n - 1; i++) { cin >> arr[i][0] >> arr[i][1] >> arr[i][2]; arr[i][3] = sqrt(((a - arr[i][0]) * (a - arr[i][0])) + ((b - arr[i][1]) * (b - arr[i][1])) + ((c - arr[i][2]) * (c - arr[i][2]))); } double aux = 1000000000; for (int i = 0; i < n - 1; i++) { for (int j = 0; j < n - 1; j++) { if (i != j) { double x = sqrt(pow(arr[j][0] - arr[i][0], 2) + pow(arr[j][1] - arr[i][1], 2) + pow(arr[j][2] - arr[i][2], 2)); aux = min(aux, arr[i][3] + arr[j][3] + x); } } } printf("%.10lf", aux / 2); return 0; }
#include <bits/stdc++.h> long n; long long x[5005] = {0}, y[5005] = {0}, z[5005] = {0}; long long a[5005][5005] = {0}; long long qrt(long long a) { return (a * a); } int main() { long i, j, k, p = 0; double ans = 0.0, s; scanf("%ld", &n); for (i = 1; i <= n; i++) scanf("%I64d%I64d%I64d", &x[i], &y[i], &z[i]); for (i = 1; i <= n; i++) for (j = i + 1; j <= n; j++) a[i][j] = qrt(x[i] - x[j]) + qrt(y[i] - y[j]) + qrt(z[i] - z[j]); for (i = 1 + 1; i <= n; i++) for (j = i + 1; j <= n; j++) { if (!p) { ans = (sqrt((double)a[1][i]) + sqrt((double)a[1][j]) + sqrt((double)a[i][j])) / 2.0; p = 1; } else { s = (sqrt((double)a[1][i]) + sqrt((double)a[1][j]) + sqrt((double)a[i][j])) / 2.0; if (ans > s) ans = s; } } printf("%.10lf\n", ans); return (0); }
#include <bits/stdc++.h> using namespace std; long double dist(long double x, long double y, long double z, long double x1, long double y1, long double z1) { long double ans = (x - x1) * (x - x1) + (y - y1) * (y - y1) + (z - z1) * (z - z1); return sqrt(ans); } long double dist2(long double x, long double y, long double z, long double x1, long double y1, long double z1) { long double ans = (x - x1) * (x - x1) + (y - y1) * (y - y1) + (z - z1) * (z - z1); return sqrt(ans) / 2; } int main() { int n; cin >> n; long double a[n], b[n], c[n]; pair<long double, int> max1[n]; for (int i = 0; i < n; i++) cin >> a[i] >> b[i] >> c[i]; for (int i = 1; i < n; i++) { max1[i].first = dist(a[0], b[0], c[0], a[i], b[i], c[i]); max1[i].second = i; } sort(max1 + 1, max1 + n); long double ans = 1e15; for (int i = 1; i < n; i++) { for (int j = i + 1; j < n; j++) { long double tmp = dist(a[max1[i].second], b[max1[i].second], c[max1[i].second], a[max1[j].second], b[max1[j].second], c[max1[j].second]); if (max1[i].first + tmp < max1[j].first) { long double f = max1[j].first - max1[i].first - tmp; f = f / 2; ans = min(ans, max1[i].first + tmp + f); } else { long double f = max1[j].first - max1[i].first; f = tmp - f; ans = min(ans, max1[j].first + f / 2); } } } cout << fixed << setprecision(8); cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; int x[5100], y[5100], z[5100]; double dst[5100]; double dest(int a, int b) { int dx = x[a] - x[b]; int dy = y[a] - y[b]; int dz = z[a] - z[b]; return sqrt(dx * dx + dy * dy + dz * dz); } int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d %d %d", &x[i], &y[i], &z[i]); for (int i = 0; i < n; i++) dst[i] = dest(0, i); double ans = 1e+100; for (int i = 1; i < n; i++) for (int j = i + 1; j < n; j++) { double tmp = dst[i] + dst[j] + dest(i, j); if (ans > tmp) ans = tmp; } ans /= 2; cout.precision(15); cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; double x[5005], y[5005], z[5005]; double dis(int i, int j) { double xx = x[i] - x[j]; double yy = y[i] - y[j]; double zz = z[i] - z[j]; return sqrt(xx * xx + yy * yy + zz * zz); } double d[5005]; int main() { int n; cin >> n; for (int i = 1; i <= n; ++i) { scanf("%lf%lf%lf", x + i, y + i, z + i); d[i] = dis(1, i); } double ans = 1e50; for (int i = 2; i <= n; ++i) for (int j = i + 1; j <= n; ++j) ans = min(ans, d[i] + d[j] + dis(i, j)); printf("%.10lf\n", ans / 2); return 0; }
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9; const long long INFLL = 1e12; const long long MOD = 1000000007; const long double eps = 1e-6; const long long MOD2 = (1 << 30) + 1; const long long dosz = 5e5; void fast_io() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } void solve() { long long n; cin >> n; vector<tuple<long double, long double, long double>> lol(n); for (tuple<long double, long double, long double> &i : lol) { long double a, b, c; cin >> a >> b >> c; i = {a, b, c}; } long double answer = INFLL; for (long long i = 1; i < n; i++) { for (long long j = i + 1; j < n; j++) { if (i == j) continue; long double a1, b1, c1, a2, b2, c2; tie(a1, b1, c1) = lol[i]; tie(a2, b2, c2) = lol[j]; long double dist = sqrt((a1 - get<0>(lol[0])) * (a1 - get<0>(lol[0])) + (b1 - get<1>(lol[0])) * (b1 - get<1>(lol[0])) + (c1 - get<2>(lol[0])) * (c1 - get<2>(lol[0]))) + sqrt((a2 - get<0>(lol[0])) * (a2 - get<0>(lol[0])) + (b2 - get<1>(lol[0])) * (b2 - get<1>(lol[0])) + (c2 - get<2>(lol[0])) * (c2 - get<2>(lol[0]))) + sqrt((a1 - a2) * (a1 - a2) + (b1 - b2) * (b1 - b2) + (c1 - c2) * (c1 - c2)); dist /= 2.0; answer = min(answer, dist); } } cout << setprecision(12) << answer << endl; } signed main() { fast_io(); long long q = 1; while (q--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; struct node { double a, b, c; }; double max(double a, double b) { return a < b ? b : a; } double min(double a, double b) { return a > b ? b : a; } node tm[5005]; double one_2[5005]; const double inf = 2147483647.0; int main() { double a, b, c; int n; int i, j; scanf("%d", &n); for (i = 1; i <= n; i++) { scanf("%lf%lf%lf", &tm[i].a, &tm[i].b, &tm[i].c); } double a1 = tm[1].a; double b1 = tm[1].b; double c1 = tm[1].c; double dis_pow2; for (j = 2; j <= n; j++) { double a2 = tm[j].a; double b2 = tm[j].b; double c2 = tm[j].c; dis_pow2 = sqrt((a1 - a2) * (a1 - a2) + (b1 - b2) * (b1 - b2) + (c1 - c2) * (c1 - c2)); one_2[j] = dis_pow2; } double ans = inf; int id; double dis2; for (id = 2; id <= n; id++) { double dis1 = one_2[id]; a1 = tm[id].a; b1 = tm[id].b; c1 = tm[id].c; for (j = 2; j <= n; j++) { if (j == id) continue; double a2 = tm[j].a; double b2 = tm[j].b; double c2 = tm[j].c; dis2 = sqrt((a1 - a2) * (a1 - a2) + (b1 - b2) * (b1 - b2) + (c1 - c2) * (c1 - c2)); double cha = fabs(dis1 - one_2[j]); ans = min(ans, dis1 + (cha + dis2) / 2); } } printf("%.16lf\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; template <class T> T abs(T x) { return x > 0 ? x : -x; } int n; int m; int x[5000], y[5000], z[5000]; double d[5000]; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d%d%d", &x[i], &y[i], &z[i]); for (int i = 1; i < n; i++) { x[i] -= x[0]; y[i] -= y[0]; z[i] -= z[0]; d[i] = sqrt(x[i] * x[i] + y[i] * y[i] + z[i] * z[i] + 0.0); } double ans = 1e10; for (int i = 1; i < n; i++) for (int j = i + 1; j < n; j++) { double cur = d[i] + d[j] + sqrt(((x[i] - x[j]) * (x[i] - x[j])) + ((y[i] - y[j]) * (y[i] - y[j])) + ((z[i] - z[j]) * (z[i] - z[j])) + 0.0); ans = min(ans, cur / 2); } printf("%.10f\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; struct point { float x, y, z; }; point a[5000]; int n; double t, dist[5000][5000]; double d(point x, point y) { return (sqrt((x.x - y.x) * (x.x - y.x) + (x.y - y.y) * (x.y - y.y) + (x.z - y.z) * (x.z - y.z))); } int main() { t = 1000000000; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%f", &a[i].x); scanf("%f", &a[i].y); scanf("%f", &a[i].z); } for (int i = 1; i < n; i++) dist[0][i] = d(a[0], a[i]); for (int i = 1; i < n; i++) for (int j = i + 1; j < n; j++) dist[i][j] = d(a[i], a[j]); for (int i = 1; i < n - 1; i++) for (int j = i + 1; j < n; j++) { t = min(t, (dist[0][i] + dist[0][j] + dist[i][j]) / 2); } printf("%.6f", t); }
#include <bits/stdc++.h> inline double sqr(double x) { return x * x; } inline double dist(int ax, int ay, int az, int bx, int by, int bz) { return sqrt(sqr(ax - bx) + sqr(ay - by) + sqr(az - bz)); } double P[5010][3]; int main() { int N; scanf("%d", &N); for (int i = 0; i < N; ++i) scanf("%lf%lf%lf", &P[i][0], &P[i][1], &P[i][2]); double res = 1e30; for (int i = 1; i < N; ++i) for (int j = i + 1; j < N; ++j) { double a = dist(P[0][0], P[0][1], P[0][2], P[i][0], P[i][1], P[i][2]); double b = dist(P[0][0], P[0][1], P[0][2], P[j][0], P[j][1], P[j][2]); double c = dist(P[i][0], P[i][1], P[i][2], P[j][0], P[j][1], P[j][2]); double m = a - b > 1e-9 ? a : b; double d = a + b - 2 * (a + b - m); res = ((res - (.5 * (c - d) + m)) > 1e-9) ? (.5 * (c - d) + m) : res; } printf("%.10f\n", res); return 0; }