Pagini recente » Cod sursa (job #2286767) | Cod sursa (job #2578294) | Cod sursa (job #55117) | Cod sursa (job #917876) | Cod sursa (job #1233924)
#include<cstdio>
#include<cmath>
#define L 50001
using namespace std;
struct COORDONATE{double x, y;} v[L];
int n, i;
double x, y, Dabs, step;
inline double DIST(double x, double y){
double s = 0.0;
for (int i = 1; i <= n; ++i){
s += sqrt((x - v[i].x)*(x - v[i].x) + (y - v[i].y)*(y - v[i].y));
}
return s;
}
int main() {
freopen("adapost2.in", "r", stdin);
freopen("adapost2.out", "w", stdout);
scanf("%d", &n);
for (i = 1; i <= n; ++i) {
scanf("%lf%lf", &v[i].x, &v[i].y);
x += v[i].x;
y += v[i].y;
}
x /= n;
y /= n;
step = 200;
Dabs = DIST(x, y);
while (step>0.0001) {
bool ok = 1;
double dx[] = { step, -step, 0, 0 };
double dy[] = { 0, 0, step, -step };
for (i = 0; i <= 3 && ok ; ++i){
if (DIST(x + dx[i], y + dy[i])<Dabs){
Dabs = DIST(x + dx[i], y + dy[i]);
x = x + dx[i];
y = y + dy[i];
ok = 0;
}
}
if (ok)
step /= 2;
}
printf("%.4lf %.4lf\n", x, y);
fclose(stdin);
fclose(stdout);
return 0;
}