Pagini recente » Cod sursa (job #1128712) | Cod sursa (job #1674757) | Cod sursa (job #1292472) | Rating Adrian Condrea (adriancondrea) | Cod sursa (job #1183385)
#include <fstream>
#include <iomanip>
#include <cmath>
using namespace std;
struct punct
{
double x;
double y;
}v[50005];
punct make_punct(double x,double y)
{
punct aux;
aux.x=x;
aux.y=y;
return aux;
}
double dist(punct a,punct b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
int n;
double tot(punct a)
{
int i;
double s=0;
for(i=1;i<=n;i++)
s+=dist(a,v[i]);
return s;
}
#define eps 0.001
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
int main()
{
ifstream cin("adapost2.in");
ofstream cout("adapost2.out");
int i;
cin>>n;
for(i=1;i<=n;i++)
cin>>v[i].x>>v[i].y;
double d=500;
punct a;
a.x=a.y=0;
bool ok;
while(d>=eps)
{
ok=true;
for(i=0;i<4;i++)
{
if(tot(a)>tot(make_punct(a.x+d*dx[i],a.y+d*dy[i])))
{
a=make_punct(a.x+d*dx[i],a.y+d*dy[i]);
ok=false;
//break;
}
}
if(ok)
d/=2;
}
cout<<fixed<<setprecision(4)<<a.x<<' '<<a.y<<'\n';
cin.close();
cout.close();
return 0;
}