题目:平衡点 / 吊打XXX
思路:
退个火?
关于退火,安利。
代码:
#include<bits/stdc++.h>
using namespace std;#define maxn 1000
#define read(x) scanf("%d",&x)
#define db double#define eps 1e-15int n;
int X[maxn+5],Y[maxn+5],w[maxn+5];db ansx=0,ansy=0;void readin() {
read(n);for(int i=1;i<=n;i++) {
read(X[i]),read(Y[i]),read(w[i]);ansx+=X[i],ansy+=Y[i];}ansx/=n,ansy/=n;
}db slv(db x,db y) {
db s=0;for(int i=1;i<=n;i++) {
db delx=x-X[i],dely=y-Y[i];s+=sqrt(delx*delx+dely*dely)*w[i];}return s;
}void mnth() {
db T=200;while(T>eps) {
db nowx=ansx+(rand()*2-RAND_MAX)*T;db nowy=ansy+(rand()*2-RAND_MAX)*T;db delta=slv(nowx,nowy)-slv(ansx,ansy);if(delta<0) ansx=nowx,ansy=nowy;else if(exp(-delta/T)*RAND_MAX>rand()) ansx=nowx,ansy=nowy;T*=0.99;}
}int main() {
srand((int)time(NULL));readin();mnth();printf("%.3lf %.3lf",ansx,ansy);return 0;
}