Cod sursa(job #2205593)

Utilizator Andrei_CotorAndrei Cotor Andrei_Cotor Data 19 mai 2018 16:06:06
Problema Adapost 2 Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.08 kb
#include<fstream>
#include<iomanip>
#include<math.h>
using namespace std;
ifstream fi("adapost2.in");
ofstream fo("adapost2.out");
int n,i;
double x,y,X[50005],Y[50005],v,d;

double dist(double x, double y)
{
    if(x<0.0 || x>1000.0 || y<0.0 || y>1000.0)
        return 1000000000;
    int i;
    double rez=0.0;
    for(i=1; i<=n; i++)
        rez=rez+sqrt((x-X[i])*(x-X[i])+(y-Y[i])*(y-Y[i]));
    return rez;
}

void s()
{
    double aux;
    aux=dist(x+v,y);
    if(aux<d)
    {
        x+=v;
        d=aux;
    }
    aux=dist(x,y+v);
    if(aux<d)
    {
        y+=v;
        d=aux;
    }
    aux=dist(x-v,y);
    if(aux<d)
    {
        x-=v;
        d=aux;
    }
    aux=dist(x,y-v);
    if(aux<d)
    {
        y-=v;
        d=aux;
    }
    v/=2.0;
    if(v<0.0001)
        return;
    s();
}

int main()
{
    fi>>n;
    for(i=1; i<=n; i++)
        fi>>X[i]>>Y[i];
    v=250.0;
    x=500.0;
    y=500.0;
    d=dist(x,y);
    s();
    fo<<setprecision(5)<<fixed<<x<<" "<<y<<"\n";
    fi.close();
    fo.close();
    return 0;
}