Pagini recente » Cod sursa (job #899548) | Cod sursa (job #2646025) | Cod sursa (job #3272000) | Cod sursa (job #1883698) | Cod sursa (job #2032263)
#include<fstream>
#include<cmath>
#include<ctime>
#include<iomanip>
using namespace std;
ifstream fin("adapost2.in");
ofstream fout("adapost2.out");
const double EPS = 1e-6;
double S, bestS;
int ok = 0;
struct Point{
double x, y;
} v[50005], P;
int n;
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 ) );
}
inline double area( Point Q ){
double A = 0.0;
for( int i = 1; i <= n; i++ )
A += dist( Q, v[i] );
return A;
}
void better( Point Q ){
S = area( Q );
if( bestS > S ){
bestS = S;
P = Q;
ok = 1;
}
}
Point make_point( double X, double Y ){
Point aux;
aux.x = X, aux.y = Y;
return aux;
}
int main(){
fin >> n;
for( int i = 1; i <= n; i++ ){
fin >> v[i].x >> v[i].y;
P.x += v[i].x;
P.y += v[i].y;
}
if( n == 1 ){
fout << v[1].x << " " << v[1].y;
return 0;
}
P.x /= n;
P.y /= n;
bestS = area( P );
clock_t T = clock();
for( double pas = 1000.0; pas > EPS && ( ( clock() - T ) / CLOCKS_PER_SEC <= 0.19 ); pas /= 2.0 ){
ok = 0;
better( make_point( P.x + pas, P.y + pas ) );
better( make_point( P.x + pas, P.y - pas ) );
better( make_point( P.x - pas, P.y - pas ) );
better( make_point( P.x - pas, P.y + pas ) );
if( ok == 1 )
pas *= 2.0;
}
fout << setprecision(5) << fixed << P.x << " " << P.y;
return 0;
}