Cod sursa(job #2225435)

Utilizator stelian2000Stelian Chichirim stelian2000 Data 27 iulie 2018 02:34:39
Problema Adapost 2 Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.88 kb
#include <bits/stdc++.h>

using namespace std;

const int dx[8]={-1,-1,0,1,1,1,0,-1},dy[8]={0,1,1,1,0,-1,-1,-1};

double vx[50010],vy[50010];
int n;

double dist(double x,double y)
{
    double s=0;
    for(int i=1;i<=n;i++)
        s+=sqrt((x-vx[i])*(x-vx[i])+(y-vy[i])*(y-vy[i]));
    return s;
}

int main()
{
    freopen("adapost2.in","r",stdin);
    freopen("adapost2.out","w",stdout);
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%lf%lf",&vx[i],&vy[i]);
    double x=500,y=500,cur=dist(x,y),l=500;
    for(int step=30;step>0;step--)
    {
        double newx=x,newy=y;
        for(int i=0;i<8;i++)
        {
            double x1=x+dx[i]*l,y1=y+dy[i]*l;
            double newcur=dist(x1,y1);
            if(newcur<cur) {cur=newcur;newx=x1;newy=y1;}
        }
        x=newx;y=newy;
        l/=2.0;
    }
    printf("%.6f %.6f",x,y);
    return 0;
}