Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma GCC optimize("O3")
- #pragma GCC target("tune=native")
- #pragma GCC optimize("fast-math,unroll-loops")
- #include <math.h>
- #include <algorithm>
- #include <set>
- #include <iostream>
- #include <vector>
- #include <queue>
- #include <map>
- #include <string>
- #include <time.h>
- #include <cassert>
- #include <functional>
- #include <memory.h>
- #include <stack>
- #include <bitset>
- #include <unordered_map>
- #include <unordered_set>
- #include <random>
- #include <chrono>
- #include <complex>
- #include <fstream>
- #include <climits>
- using namespace std;
- typedef unsigned long long ull;
- typedef long long ll;
- typedef unsigned u;
- typedef long double ld;
- typedef vector<vector<int>> vvi;
- typedef unsigned char uc;
- typedef unsigned short us;
- typedef complex<double> cd;
- #define INF 1000000000
- #define LLINF 1000000000000000000LL
- #define EPS 1e-9l
- #define pii pair<int, int>
- const int DEBUG = 0;
- #ifdef LOCAL
- mt19937 gen(228);
- #else
- mt19937 gen((u)chrono::high_resolution_clock::now().time_since_epoch().count());
- #endif
- #pragma comment(linker, "/STACK:76777216")
- struct pt
- {
- double x, y, z;
- };
- double sqr(double x)
- {
- return x * x;
- }
- double dist(const pt& a, const pt& b)
- {
- return sqrt(sqr(a.x - b.x) + sqr(a.y - b.y) + sqr(a.z - b.z));
- }
- pt pts[3];
- double calcDist(pt p)
- {
- double res = 0;
- for (int i = 0; i < 3; i++)
- res += dist(p, pts[i]);
- return res;
- }
- double calcZ(double x, double y, double& z)
- {
- double l = -1e9, r = 1e9;
- while (r - l > 1e-9)
- {
- double m1 = l + (r - l) / 3;
- double m2 = r - (r - l) / 3;
- if (calcDist(pt{ x, y, m1 }) < calcDist(pt{ x, y, m2 }))
- r = m2;
- else
- l = m1;
- }
- l = (l + r) / 2;
- z = l;
- return calcDist(pt{ x, y, z });
- }
- double calcY(double x, double& y, double& z)
- {
- double l = -1e9, r = 1e9;
- while (r - l > 1e-9)
- {
- double m1 = l + (r - l) / 3;
- double m2 = r - (r - l) / 3;
- if (calcZ(x, m1, z) < calcZ(x, m2, z))
- r = m2;
- else
- l = m1;
- }
- l = (l + r) / 2;
- y = l;
- return calcZ(x, y, z);
- }
- double calcX(double& x, double& y, double& z)
- {
- double l = -1e9, r = 1e9;
- while (r - l > 1e-9)
- {
- double m1 = l + (r - l) / 3;
- double m2 = r - (r - l) / 3;
- if (calcY(m1, y, z) < calcY(m2, y, z))
- r = m2;
- else
- l = m1;
- }
- l = (l + r) / 2;
- x = l;
- return calcY(x, y, z);
- }
- int main()
- {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.setf(cout.fixed);
- cout.precision(12);
- auto START_TIME = chrono::high_resolution_clock::now();
- for (int i = 0; i < 3; i++)
- {
- cin >> pts[i].x >> pts[i].y >> pts[i].z;
- }
- double x, y, z;
- cout << calcX(x, y, z);
- #ifdef LOCAL
- cerr.precision(3);
- cerr << "\nWorking time: " << chrono::duration<double>(chrono::high_resolution_clock::now() - START_TIME).count() << " sec.";
- #endif
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement