Cod sursa(job #1046072)

Utilizator the@EyE@Postavaru Stefan the@EyE@ Data 2 decembrie 2013 17:23:26
Problema Adapost 2 Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.93 kb
#include<stdio.h>
#include<math.h>
#define INF 50001

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

int main()
{
    freopen("adapost2.in","r",stdin);
    freopen("adapost2.out","w",stdout);
    scanf("%d",&n);
    double a=0,b=0,lr=1.0f;
    for(int i=0;i<n;++i){scanf("%lf%lf",&x[i],&y[i]);a+=x[i];b+=y[i];}
    double prev=0,e=0;
    a/=n;b/=n;
    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;
}