模拟退火。
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
const double tmax=10000,r=0.995,eps=1e-5;
const int maxn=10010;
int xx[maxn],yy[maxn],w[maxn],n;
double cal(double x,double y)
{
double ret=0;
for (int i=1;i<=n;i++)
ret+=sqrt((x-xx[i])*(x-xx[i])+(y-yy[i])*(y-yy[i]))*w[i];
return ret;
}
double get(double lim)
{
return (double)rand()/RAND_MAX*(2*lim)-lim;
}
int main()
{
srand(233);
double x=0,y=0,x1,y1,now,tem;
scanf("%d",&n);
for (int i=1;i<=n;i++) scanf("%d%d%d",&xx[i],&yy[i],&w[i]),x+=xx[i],y+=yy[i];
x/=n;
y/=n;
now=cal(x,y);
for (double t=tmax;t>eps;t*=r)
{
x1=x+get(t);
y1=y+get(t);
tem=cal(x1,y1);
if (tem<now||exp((now-tem)/t)>get(0.5)+0.5)
{
x=x1;
y=y1;
now=tem;
}
}
for (double t=0.1;t>eps;t*=r)
{
x1=x+get(t);
y1=y+get(t);
tem=cal(x1,y1);
if (tem<now)
{
x=x1;
y=y1;
now=tem;
}
}
printf("%.3f %.3f\n",x,y);
}