每次随机改变当前中心坐标 然后退火 退火完成后在周围附近在搜索几次(没这个我一直过不了样例)
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<queue>
#include<cmath>
#define PF printf
#define SF scanf
using namespace std;
typedef long long LL;
const int MAXN = 100000;
struct Node {
double x, y, g;
} A[MAXN+10], ans;
double Min;
int n;
inline double dis(const Node &a,const Node &b) {
return sqrt((a.x-b.x) * (a.x-b.x) + (a.y-b.y) * (a.y-b.y));
}
inline double Rand() {
return rand() % 10000 / 10000.0;
}
double calc(const Node &t) {
double ret = 0;
for(int i = 1; i <= n; i++) ret += dis(t, A[i]) * A[i].g;
if(ret < Min) {
Min = ret; ans = t;
}
return ret;
}
void SA(double T) {
Node Now = ans;
while(T > 0.001) {
Node New;
New.x = Now.x + T * (Rand() * 2 - 1);
New.y = Now.y + T * (Rand() * 2 - 1);
double dE = calc(Now) - calc(New);
if(dE > 0 || exp(dE/T) > Rand()) Now = New;
T *= 0.97;
}
for(int i = 1; i <= 125; i++) calc( (Node) { ans.x + T*(Rand()*2-1), ans.y + T*(Rand()*2-1) } );
}
int main() {
SF("%d", &n);
srand(n+23333);
for(int i = 1; i <= n; i++) {
SF("%lf%lf%lf", &A[i].x, &A[i].y, &A[i].g);
ans.x += A[i].x; ans.y += A[i].y;
}
ans.x /= n; ans.y /= n;
Min = calc(ans);
SA(80000);
PF("%.3f %.3f", ans.x, ans.y);
}