爬山做貌似一个过不去
代码
#include<bits/stdc++.h>
using namespace std;
struct pointt
{
double x,y,wei;
}point[1005],cans,ans;
int n;
double dis[2005];
double calc_dis(double a,double b)
{
return sqrt(a*a+b*b);
}
int main()
{
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%lf %lf %lf",&point[i].x,&point[i].y,&point[i].wei);
ans.x+=point[i].x/n;
ans.y+=point[i].y/n;
}
for(double t=10000;;t*=0.999)
{
for(int i=1;i<=n;i++)
dis[i]=calc_dis(point[i].x-ans.x,point[i].y-ans.y);
cans.x=cans.y=0;
for(int i=1;i<=n;i++)
cans.x+=(point[i].x-ans.x)*point[i].wei/dis[i],cans.y+=(point[i].y-ans.y)*point[i].wei/dis[i];
ans.x+=cans.x*t;
ans.y+=cans.y*t;
if(abs(cans.x*t)<0.00001 && abs(cans.y*t)<0.00001) break;
}
printf("%.3lf %.3lf",ans.x,ans.y);
return 0;
}