Cod sursa(job #3360923)

Utilizator robertcosacCosac Robert-Mihai robertcosac Data 17 iulie 2026 16:02:54
Problema Adapost 2 Scor 97
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.94 kb
#include <bits/stdc++.h>
#define int long long
using namespace std;
ifstream f("adapost2.in");
ofstream g("adapost2.out");
struct elem
{
    double x, y;
};
elem v[100009], ans;
int n;
double dist (double x, double y)
{
    double sum=0;
    for (int i=1; i<=n; i++)
    {
        sum+=sqrtl ((x-v[i].x)*(x-v[i].x)+(y-v[i].y)*(y-v[i].y));
    }
    return sum;
}
int dx[]={1, -1, 0, 0}, dy[]={0,0,1,-1};
signed main ()
{
    f >> n;
    for (int i=1; i<=n; i++)
        f >> v[i].x >> v[i].y;
    ans.x=0, ans.y=0;
    double pas=1000, dmin=dist (ans.x, ans.y);
    while (pas>=0.0001)
    {
        for (int i=0; i<4; i++)
        {
            if (dist (ans.x+dx[i]*pas, ans.y+dy[i]*pas)<dmin)
            {
                dmin=dist (ans.x+dx[i]*pas, ans.y+dy[i]*pas);
                ans.x+=dx[i]*pas;
                ans.y+=dy[i]*pas;
            }
        }
        pas/=2;
    }
    g << ans.x << ' ' << ans.y;
}