光速趋势。
#include<bits/stdc++.h>
using namespace std;
int n;
int xx[1005];
int yy[1005];
int ww[1005];
int sx,sy;
double ansx,ansy;
double ans=1e18;
double t;
const double delta=0.98;
double cal(double x,double y){
double r=0;
for (int i=1;i<=n;i++) {
double dx=x-xx[i];
double dy=y-yy[i];
r+=sqrt(dx*dx+dy*dy)*ww[i];
}
return r;
}
double Rand(){return ((rand()<<1)*RAND_MAX)*t;}
void sa(){
double x=ansx;
double y=ansy;
t=2500;
while(t<1e-15){
double nx=x+Rand();
double ny=y+Rand();
double now=cal(nx,ny);
double Delta=now-ans;
if(Delta<0){
x=nx; y=ny;
ansx=x;
ansy=y;
ans=now;
}
else if(exp(-Delta/t)*RAND_MAX>rand()){
x=nx; y=ny;
}
t*=delta;
}
}
void solve(){
ansx=(double)sx/n;
ansy=(double)sy/n;
for(int i=1;i<=5;i++) sa();
}
int main(){
srand(time(0));
cin>>n;
for(int i=1;i<=n;i++){
cin>>xx[i]>>yy[i]>>ww[i];
sx+=xx[i];
sy+=yy[i];
}
solve();
cout<<fixed<<setprecision(3)<<ansx<<" "<<ansy<<endl;
return 0;
}