Pagini recente » Cod sursa (job #182939) | Cod sursa (job #1608661) | Cod sursa (job #2299264) | Cod sursa (job #2310419) | Cod sursa (job #2066307)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("adapost2.in");
ofstream fout("adapost2.out");
//const int dx[] = {-1, -1, -1, 0, 1, 1, 1, 0};
//const int dy[] = {-1, 0, 1, 1, 1, 0, -1, -1};
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
const int NMax = 5e4 + 50;
const double eps = 1e-12;
int n;
pair < double, double > points[NMax];
double pointsDistance(const pair < double, double > &a, const pair < double, double > &b) {
return sqrt((a.first - b.first) * (a.first - b.first) + (a.second - b.second) * (a.second - b.second));
}
double allDistance(const pair < double, double > &x) {
double ret = (double)0.0;
for(int i = 1; i <= n; ++i) {
ret += pointsDistance(points[i], x);
}
return ret;
}
int main() {
fin >> n;
for(int i = 1; i <= n; ++i) fin >> points[i].first >> points[i].second;
pair < double, double > ans;
for(int i = 1; i <= n; ++i) {
ans.first += points[i].first;
ans.second += points[i].second;
}
ans.first /= (double)n;
ans.second /= (double)n;
pair < double, double > auxPair;
double auxDist, best;
double dist = allDistance(ans);
double hi = 1000.0;
while(hi >= 0.0000000001) {
best = dist;
for(int d = 0; d < 4; ++d) {
auxPair = {ans.first + dx[d] * hi, ans.second + dy[d] * hi};
auxDist = allDistance(auxPair);
if(abs(best - auxDist) < eps) continue;
if(best > auxDist) {
best = auxDist;
ans = auxPair;
d = 0;
}
}
hi /= 2.0;
}
fout << fixed << setprecision(4) << ans.first << " " << ans.second;
return 0;
}