Pagini recente » Rating roxana moisa (roxana22) | Cod sursa (job #1256866) | Cod sursa (job #1973698) | Profil Jitianu_Alexandra_Mihaela_323CC | Cod sursa (job #929247)
Cod sursa(job #929247)
#include <iostream>
#include <fstream>
#include <cmath>
#include <iomanip>
#define per pair<double,double>
#define mp make_pair
#define DN 50005
#define EPS 1e-5
#define x first
#define y second
using namespace std;
int n;
per p[DN],pct;
double d=512.0,sum=1<<30;
int ii[]={1,-1,0,0},jj[]={0,0,-1,1};
ifstream f("adapost2.in");
ofstream g("adapost2.out");
double dist(per a,per b)
{
return sqrt( (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y) );
}
double get_sum ( per x )
{
double S=0;
for(int i=1;i<=n;++i)
S+=dist(x,p[i]);
return S;
}
void caut()
{
for(double d=16.0;d>=EPS;d*=0.5)
{
for(int t=0;t<4;++t)
{
per new_point = mp(pct.x + ii[t]*d , pct.y + jj[t] *d );
double new_sum = get_sum( new_point );
if(new_sum<sum)
{
sum=new_sum;
pct=new_point;
d*=2;
break;
}
}
}
g<<fixed<<setprecision(4)<<pct.x<<" "<<pct.y;
}
int main()
{
f>>n;
for(int i=1;i<=n;++i)
{
f>>p[i].x>>p[i].y;
pct.x+=p[i].x;
pct.y+=p[i].y;
}
pct.x/=n;
pct.y/=n;
get_sum(pct);
caut();
return 0;
}