# include <stdio.h>
# include <string.h>
# include <math.h>
# include <stdlib.h>
using namespace std;

# define N 105
# define eps 1e-8

int n;
 struct point {
double x, y;
 void read() {scanf("%lf %lf", &x, &y);}
}p[N];
 double dic[4][2] = { {0.0, 1.0}, {0.0, -1.0}, {1.0, 0.0}, {-1.0, 0.0}};
 double dis(point a, point b) {
return sqrt( (a.x-b.x) * (a.x-b.x) + (a.y-b.y) * (a.y-b.y) );
}
 double dis_all(point o) {
double s = 0.0;
for(int i = 0; i < n; i ++) s += dis(o, p[i]);
return s;
}

 int main() {
bool flag;
double mmin, dist, step;
point o, temp;
 while(scanf("%d", &n) != EOF) {
for(int i = 0; i < n; i ++) p[i].read();
o = p[0];
mmin = dis_all(o);
 for(step = 1000.0; step > eps; step /= 2) {
flag = 1;
 while(flag) {
flag = 0;
 for(int i = 0; i < 4; i ++) {
temp.x = o.x + dic[i][0] * step;
temp.y = o.y + dic[i][1] * step;
dist = dis_all(temp);
 if(dist < mmin) {
mmin = dist;
o = temp;
flag = 1;
}
}
}
}
printf("%.0lf\n", mmin);
}
}

|