Cod sursa(job #2110596)

Utilizator cella.florescuCella Florescu cella.florescu Data 20 ianuarie 2018 21:51:18
Problema Adapost 2 Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.09 kb
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 5e4;
const double CT = sqrt(3) / 2;

double x[MAXN], y[MAXN];
double dirx[] = {0, CT, CT, 0, -CT, -CT}, diry[] = {1, 0.5, -0.5, -1, -0.5, 0.5, };

int main()
{
    int n;
    ifstream fin("adapost2.in");
    fin >> n;
    double xp = 0.0, yp = 0.0;
    for (int i = 0; i < n; ++i) {
      fin >> x[i] >> y[i];
      xp += x[i]; yp += y[i];
    }
    fin.close();
    xp /= n; yp /= n;
    double mv = 150;
    for (int step = 0; step < (n <= 10000 ? 60 : 23); ++step) {
      int dir;
      double minD = 1e10;
      for (int d = 0; d < 8; ++d) {
        double dst = 0.0, a = xp + mv * dirx[d], b = yp + mv * diry[d];
        for (int i = 0; i < n; ++i)
          dst += sqrt((a - x[i]) * (a - x[i]) + (b - y[i]) * (b - y[i]));
        if (dst < minD) {
          minD = dst;
          dir = d;
        }
      }
      xp += mv * dirx[dir]; yp += mv * diry[dir];
      mv *= 0.6;
    }
    ofstream fout("adapost2.out");
    fout << setprecision(4) << fixed << xp << " " << yp;
    fout.close();
    return 0;
}