Cod sursa(job #1131574)

Utilizator otto1Palaga Vicentiu-Octavian otto1 Data 28 februarie 2014 21:46:16
Problema Adapost 2 Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.91 kb
#include<stdio.h>
#include<math.h>
#define INF 50001

int n;
double x[INF],y[INF];

int main()
{
    freopen("adapost2.in","r",stdin);
    freopen("adapost2.out","w",stdout);
    scanf("%d",&n);
    double a=0,b=0,lr=0.01f;
    for(int i=0;i<n;++i){scanf("%lf%lf",&x[i],&y[i]);a+=x[i]/n;b+=y[i]/n;}
    double prev=0,e=0;
    int t=0;double add=2;
    if(n==1){printf("%lf %lf\n",x[0],y[0]);return 0;}
    do
    {
        prev=e;
        e=0;
        double preva=a,prevb=b,da=0,db=0;
        for(int i=0;i<n;++i)
        {
            double sub=sqrt((preva-x[i])*(preva-x[i])+(prevb-y[i])*(prevb-y[i]));
            e+=sub;
            da+=(preva-x[i])/sub;
            db+=(prevb-y[i])/sub;
        }
        a-=da*add;
        b-=db*add;
        add/=2;
        if(add<0.002966)add=0.002966;
    ++t;
    }while(fabs(e-prev)>0&&t*n<2450000);

    printf("%lf %lf\n",a,b);
    return 0;
}