Cod sursa(job #1391588)

Utilizator alex_HarryBabalau Alexandru alex_Harry Data 18 martie 2015 02:14:46
Problema Adapost 2 Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.22 kb
#include <fstream>
#include <cmath>
#include <iomanip>
using namespace std;
ifstream f("adapost2.in");
ofstream g("adapost2.out");
int dx[]={0,0,-1,1},N;
int dy[]={-1,1,0,0};
const double eps = 0.0001;
struct point{
double x,y;
} Array[50005];
void Read()
{
    f>>N;
    for(int i=1;i<=N;i++)
        f>>Array[i].x>>Array[i].y;
}
inline double dist(point a,point b)
{
    return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
double Distance(point a)
{
    double ans=0;
    for(int i=1;i<=N;i++)
        ans+=dist(Array[i],a);
    return ans;
}
void Solve()
{
    point p;
    p.x=500;p.y=500;
    double step=500,d=Distance(p);
    bool change;
    while(step>eps)
    {
        change=1;
        point aux;
        for(int i=0;i<4;i++)
        {
            aux.x=p.x+dx[i]*step;
           aux.y=p.y+dy[i]*step;
            double D=Distance(aux);
            if(D<d)
            {
                change=0;
                d=D;
                p.x+=dx[i]*step;
                p.y+=dy[i]*step;break;
            }
        }
        if(change==1)
            step/=2;
    }
    g<<fixed<<setprecision(4)<<p.x<<" "<<p.y<<"\n";
}
int main()
{
    Read();
    Solve();
    return 0;
}