Pagini recente » Cod sursa (job #2345273) | Borderou de evaluare (job #1098984) | Cod sursa (job #455681) | Cod sursa (job #986309) | Cod sursa (job #1564260)
#include <stdio.h>
#include <math.h>
#define MAXN 50000
double l[MAXN], c[MAXN];
int d[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
inline double dist(double x, double y, int n){
int i;
double d = 0;
for(i = 0; i < n; i++){
d += sqrt((x - l[i]) * (x - l[i]) + (y - c[i]) * (y - c[i]));
}
return d;
}
int main(){
FILE *in = fopen("adapost2.in", "r");
int n, i;
double x = 0, y = 0, pas;
fscanf(in, "%d", &n);
for(i = 0; i < n; i++){
fscanf(in, "%lf%lf", &l[i], &c[i]);
x += l[i]; y += c[i];
}
x /= n; y /= n;
pas = 1;
while(pas > 0.00001){
for(i = 0; i < 4; i++){
while(dist(x + d[i][0] * pas, y + d[i][1] * pas, n) < dist(x, y, n)){
x += d[i][0] * pas;
y += d[i][1] * pas;
}
}
pas /= 2;
}
FILE *out = fopen("adapost2.out", "w");
fprintf(out, "%.4lf %.4lf", x, y);
fclose(out);
return 0;
}