# Cod sursa(job #1874767)

Utilizator Data 10 februarie 2017 13:35:13 Adapost 2 85 cpp done Arhiva de probleme 2.74 kb
``````// TEAM CORNELL
#include<bits/stdc++.h>

#define fs first
#define sc second
#define mp make_pair
#define pb push_back
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef pair<double,double> pdd;
#define eps 0.0001
ll N;
#define Nmax 1010100
double vx[202020];
double vy[202020];
double dist(double x1, double y1, double x2, double y2) {
return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
}

double getdist(pdd x) {
double ret = 0;
for(int i=0;i<N;++i) {
ret += dist(x.fs,x.sc,vx[i],vy[i]);
}
return ret;
}
int T=0;
map<double,int> h;
int main() {
cin.sync_with_stdio(false);
// cin >> T;
T=1;
while(T--) {
double start = 1;
while(start < 10000000) start *= 2;
pdd cur=mp(0,0);
scanf("%d",&N);
for(int i=0;i<N;++i) {
double a,b;
scanf("%lf%lf",&a,&b);
cur.fs += a;
cur.sc += b;
vx[i] = a;
vy[i] = b;
}
// cout << v.size() << endl;
//cout << v.size() << endl;
cur.fs /= N;
cur.sc /= N;
//cout << v.size() << endl;
double curd = getdist(cur);
int NRQ = 0;
while(start > eps) {
int ok = 0;
double curd = getdist(cur);
double r = getdist(mp(cur.fs+start,cur.sc));
double l = getdist(mp(cur.fs-start,cur.sc));
double d = getdist(mp(cur.fs,cur.sc-start));
double u = getdist(mp(cur.fs,cur.sc+start));
if(r < curd && u > curd && d > curd) {
cur = mp(cur.fs+start,cur.sc);
continue;
}
if(l < curd && u > curd && d > curd) {
cur = mp(cur.fs-start,cur.sc);
continue;
}
if(u < curd && l > curd && r > curd) {
cur = mp(cur.fs,cur.sc+start);
continue;
}
if(d < curd && l > curd && r > curd) {
cur = mp(cur.fs,cur.sc-start);
continue;
}
if(d <curd && l < curd) {
double d1 = (curd - d);
double d2 = (curd - l);
cur.fs -= d2 / (d1+d2) * start;
cur.sc -= d1 / (d1+d2) * start;
continue;
}
if(d <curd && r < curd) {
double d1 = (curd - d);
double d2 = (curd - r);
cur.fs += d2 / (d1+d2) * start;
cur.sc -= d1 / (d1+d2) * start;
continue;
}
if(u < curd && r < curd) {
double d1 = (curd - u);
double d2 = (curd - r);
cur.fs += d2 / (d1+d2) * start;
cur.sc += d1 / (d1+d2) * start;
continue;
}
if(u < curd && l < curd) {
double d1 = (curd - u);
double d2 = (curd - l);
cur.fs -= d2 / (d1+d2) * start;
cur.sc += d1 / (d1+d2) * start;
continue;
}
start = start / 2.0;

}
printf("%.12lf %.12lf\n",cur.fs, cur.sc);
}
}

``````