Pagini recente » Cod sursa (job #1523200) | Cod sursa (job #2536368) | Cod sursa (job #2027196) | Cod sursa (job #1637250) | Cod sursa (job #918152)
Cod sursa(job #918152)
#include <fstream>
#include <iomanip>
#include <cmath>
using namespace std;
ifstream F("adapost2.in");
ofstream G("adapost2.out");
#define x first
#define y second
typedef pair<double, double> Pair;
const double EPS = 1e-4;
const int Nmax = 50010;
const double dx[4]= { 1 , 0 , -1, 0 };
const double dy[4]= { 0 , -1, 0 , 1 };
int N;
Pair Point,A[Nmax];
double Best;
inline double sqr(double X)
{ return X*X; }
double Dist(const Pair& P)
{
double Point=0;
for (int i=1;i<=N;++i)
Point += sqrt( sqr(P.x-A[i].x) + sqr(P.y-A[i].y) );
return Point;
}
int main()
{
F>>N;
for (int i=1;i<=N;++i)
{
F>>A[i].x>>A[i].y;
Point.x += A[i].x;
Point.y += A[i].y;
}
Point.x /= 1.0*N ;
Point.y /= 1.0*N ;
Best = Dist(Point);
for (double Move=16; Move>EPS; Move/=2.0)
for (int i=0;i<4;++i)
{
Pair Next;
Next.x = Point.x + Move * dx[i];
Next.y = Point.y + Move * dy[i];
double Now = Dist( Next );
if ( Now < Best )
{
Best = Now;
Point = Next;
Move *= 2;
break;
}
}
G<<fixed<<setprecision(4)<<Point.x<<' '<<Point.y<<'\n';
}