Pagini recente » Cod sursa (job #1895449) | Cod sursa (job #2586462) | Cod sursa (job #2917591) | Cod sursa (job #323821) | Cod sursa (job #2066276)
#include <bits/stdc++.h>
using namespace std;
typedef double ld;
ifstream fin("adapost2.in");
ofstream fout("adapost2.out");
const ld dx[] = {-1, -1, -1, 0, 1, 1, 1, 0};
const ld dy[] = {-1, 0, 1, 1, 1, 0, -1, -1};
const int NMax = 5e4 + 50;
const double eps = 1e-4;
int n;
pair < ld, ld > points[NMax];
ld power(const ld &x) {
return x * x;
}
ld pointsDistance(const pair < ld, ld > &a, const pair < ld, ld > &b) {
return sqrtl(power(a.first - b.first) + power(a.second - b.second));
}
ld allDistance(const pair < ld, ld > &x) {
ld ret = (double)0.0;
for(int i = 1; i <= n; ++i) {
ret += pointsDistance(points[i], x);
}
return ret;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
fin >> n;
for(int i = 1; i <= n; ++i) fin >> points[i].first >> points[i].second;
pair < ld, ld > ans = points[0];
int dir = -1;
pair < ld, ld > auxPair;
ld auxDist, best;
ld dist = allDistance(ans);
ld hi = 1000.0;
while(hi >= 0.0000000001) {
dir = -1;
best = dist;
for(int d = 0; d < 8; ++d) {
auxPair = {ans.first + dx[d] * hi, ans.second + dy[d] * hi};
auxDist = allDistance(auxPair);
if(best > auxDist) {
best = auxDist;
dir = d;
}
}
if(dir != -1) {
ans.first += dx[dir] * hi;
ans.second += dy[dir] * hi;
}
hi /= 2.0;
}
fout << fixed << setprecision(4) << ans.first << " " << ans.second;
return 0;
}