Pagini recente » Cod sursa (job #2129377) | Cod sursa (job #2493142) | Cod sursa (job #869880) | Cod sursa (job #1971671) | Cod sursa (job #814735)
Cod sursa(job #814735)
#include <cstdio>
#include <cmath>
#include <iostream>
#include <fstream>
#define eps 0.0001
using namespace std;
ifstream input("adapost2.in");
ofstream output("adapost2.out");
struct MyPoint{
double x , y;
void initialize( double xa, double ya ){
this->x = xa;
this->y = ya;
}
};
double myDistance (const MyPoint &a,const MyPoint &b ){
return sqrt( (a.x - b.x)*(a.x - b.x) + (a.y - b.y)*(a.y-b.y) );
}
int N;
int main(){
input >> N;
MyPoint *points = new MyPoint[N];
for( int i = 0 ; i < N; i++ ){
double x,y;
input >> x >> y;
points[i].initialize(x,y);
}
MyPoint p ;
p.x = p.y = 0;
for( int i = 0 ; i < N ; i++ ){
p.x += points[i].x;
p.y += points[i].y;
}
p.x /= N;
p.y /= N;
MyPoint newp;
newp.x = newp.y = 0;
double weight = 0;
double val;
while(1){
for( int i = 0 ; i < N; i++ ){
val = myDistance( points[i], p );
weight += 1/val;
newp.x += points[i].x/val ;
newp.y += points[i].y/val;
}
newp.x = newp.x/weight;
newp.y = newp.y/weight;
weight = 0;
if( myDistance( newp, p ) < eps )
break;
p = newp;
newp.x = newp.y = 0;
}
output.precision(5);
output<< newp.x<<" "<<newp.y;
return 0;
}