Cod sursa(job #814741)

Utilizator lucky1992Ion Ion lucky1992 Data 15 noiembrie 2012 23:23:45
Problema Adapost 2 Scor 95
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.39 kb
#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;

MyPoint points[50001];
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;
   p.x = 0;
   p.y = 0;
   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<< newp.x<<" "<<newp.y;
     input.close();
     
     //delete []points;
   return 0;
}