Cod sursa(job #1046353)

Utilizator the@EyE@Postavaru Stefan the@EyE@ Data 2 decembrie 2013 20:56:52
Problema Adapost 2 Scor 67
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.74 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.05f;
    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;
    do
    {
        prev=e;
        e=0;
        double preva=a,prevb=b;
        for(int i=0;i<n;++i)
        {
            double sub=sqrt(pow(preva-x[i],2)+pow(prevb-y[i],2));
            e+=sub;
            a-=lr*(preva-x[i])/sub;
            b-=lr*(prevb-y[i])/sub;
        }
    ++t;
    }while(fabs(e-prev)>0.0000000001&&t*n<3000000);

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