Pagini recente » Cod sursa (job #1680796) | Cod sursa (job #1650358) | Monitorul de evaluare | Cod sursa (job #1350414) | Cod sursa (job #587055)
Cod sursa(job #587055)
#include <fstream>
#include <iomanip>
#include <cmath>
using namespace std;
const char InFile[]="adapost2.in";
const char OutFile[]="adapost2.out";
const int MaxN=50111;
const float EPS=1.0e-5f;
const int DIR=4;
const float dx[]={0,0,1,-1};
const float dy[]={1,-1,0,0};
struct s_point
{
s_point(float _x=0.0, float _y=0.0):x(_x),y(_y){}
float x,y;
inline float dist(const s_point &a) const
{
float dx(x-a.x),dy(y-a.y);
return (float)(sqrt((double)(dx*dx+dy*dy)));
}
};
ifstream fin(InFile);
ofstream fout(OutFile);
int N;
s_point v[MaxN],G,solpoint;
float sol;
inline float sumdist(const s_point &P)
{
float sum=0.0;
for(register int i=1;i<=N;++i)
{
sum+=P.dist(v[i]);
}
return sum;
}
int main()
{
fin>>N;
for(register int i=1;i<=N;++i)
{
fin>>v[i].x;
fin>>v[i].y;
G.x+=v[i].x;
G.y+=v[i].y;
}
fin.close();
G.x/=(float)N;
G.y/=(float)N;
solpoint=G;
sol=sumdist(solpoint);
for(float step=512.0;step>=EPS;step*=0.5)
{
for(register int i=0;i<DIR;++i)
{
float d=sumdist(s_point(solpoint.x+dx[i]*step,solpoint.y+dy[i]*step));
if(d<sol)
{
sol=d;
solpoint.x+=dx[i]*step;
solpoint.y+=dy[i]*step;
step*=2.0;
break;
}
}
}
fout<<setprecision(4)<<std::fixed;
fout<<solpoint.x<<" "<<solpoint.y;
fout.close();
return 0;
}