Pagini recente » Cod sursa (job #187576) | Cod sursa (job #2806856) | Cod sursa (job #2846075) | Cod sursa (job #2220312) | Cod sursa (job #1083802)
#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;
}