先坑着,联赛活着回来的话我就写(意思就是我绝对不会写了)
1 //minamoto 2 #include<cstdio> 3 #include<cmath> 4 #include<ctime> 5 #include<cstdlib> 6 #define RD T*(rand()*2-RAND_MAX) 7 #define double long double 8 const int N=1005; 9 double x[N],y[N],w[N]; 10 const double D=0.97,EPS=1e-14; 11 int n; 12 inline double calc(double x0,double y0){ 13 double res=0,dx,dy; 14 for(int i=1;i<=n;++i){ 15 dx=x[i]-x0,dy=y[i]-y0; 16 res+=sqrt(dx*dx+dy*dy)*w[i]; 17 } 18 return res; 19 } 20 int main(){ 21 double bx=0,by=0,best,ans,T,x0,y0,x1,y1,res; 22 // freopen("testdata.in","r",stdin); 23 int times=1; 24 scanf("%d",&n); 25 for(int i=1;i<=n;++i){ 26 scanf("%Lf%Lf%Lf",&x[i],&y[i],&w[i]); 27 bx+=x[i],by+=y[i]; 28 } 29 best=ans=calc(bx/=n,by/=n); 30 srand(time(0)); 31 while(times--){ 32 ans=best,x0=bx,y0=by; 33 for(T=100000;T>EPS;T*=D){ 34 x1=x0+RD;y1=y0+RD; 35 res=calc(x1,y1); 36 if(best>res) best=res,bx=x1,by=y1; 37 if(ans>res||exp((ans-res)/T)>(double)rand()/RAND_MAX) 38 ans=res,x0=x1,y0=y1; 39 } 40 } 41 printf("%.3Lf %.3Lf ",bx,by); 42 return 0; 43 }