Cod sursa(job #1046463)

Utilizator the@EyE@Postavaru Stefan the@EyE@ Data 2 decembrie 2013 22:27:19
Problema Adapost 2 Scor 95
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.84 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;
    do
    {
        prev=e;
        e=0;
        double preva=a,prevb=b,da=0,db=0;
        for(int i=0;i<n;++i)
        {
            double sub=sqrt(pow(preva-x[i],2)+pow(prevb-y[i],2));
            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<2500000);

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