Pagini recente » Cod sursa (job #2489025) | Cod sursa (job #1907110) | Cod sursa (job #485712) | Cod sursa (job #1689858) | Cod sursa (job #2077650)
#include <fstream>
#include <cmath>
#include <iomanip>
using namespace std;
ifstream f("adapost2.in");
ofstream g("adapost2.out");
int n, i, j;
const double EPS = 1e-3;
double ax[50005], ay[50005], x, y, xx, yy, p;
double dx[] = {0,1,0,-1}, dy[] = {1,0,-1,0};
double d2(double x, double y, double xx, double yy) {
return sqrt((xx-x)*(xx-x)+(yy-y)*(yy-y));
}
double dist(double x, double y) {
int i;
double sum = 0;
for (i = 1; i <= n; i++)
sum += d2(ax[i],ay[i],x,y);
return sum;
}
int main() {
f >> n;
for (i = 1; i <= n; i++) {
f >> ax[i] >> ay[i];
x += ax[i], y += ay[i];
}
x /= n, y /= n;
double minim = dist(x,y), t;
p = 100;
for (;p>EPS;) {
bool ok = 1;
for (i = 0; i < 4; i++) {
xx = x+p*dx[i];
yy = y+p*dy[i];
t = dist(xx,yy);
if (t < minim) {
minim = t;
x = xx, y = yy;
ok = 0;
break;
}
}
if (ok) p/=2;
}
g << fixed << setprecision(4) << x << ' ' << y;
return 0;
}