Cod sursa(job #1083802)

Utilizator the@EyE@Postavaru Stefan the@EyE@ Data 16 ianuarie 2014 13:55:23
Problema Matrice 2 Scor 0
Compilator cpp Status done
Runda Teme Pregatire ACM Unibuc 2013 Marime 0.92 kb
#include<stdio.h>
#include<math.h>
#define INF 50001

int n;
double x[INF],y[INF];
double lrCoefficient=0.05f,maxLR=50.0f,minLR=0.01f;

int main()
{
    freopen("adapost2.in","r",stdin);
    freopen("adapost2.out","w",stdout);
    scanf("%d",&n);
    double a=0,b=0,lr=10.0f;
    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;
    do
    {
       if(lr<minLR)lr=minLR;
       else if(lr>maxLR)lr=maxLR;
        prev=e;
        e=0;
        double preva=a,prevb=b,prevLR=lr;
        for(int i=0;i<n;++i)
        {
            double sub=sqrt(pow(preva-x[i],2)+pow(prevb-y[i],2));
            e+=sub;
            a-=prevLR*(preva-x[i])/sub;
            b-=prevLR*(prevb-y[i])/sub;
            lr-=lrCoefficient*(prevLR*(preva-x[i])/sub+prevLR*(prevb-y[i])/sub);
        }

    }while(fabs(e-prev)>0.0000000001);

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