爬山法89pts求助
查看原帖
爬山法89pts求助
219300
MapleOklia_LucasRay楼主2022/11/18 00:29
#include<bits/stdc++.h>
using namespace std;
constexpr int maxn = 1e4 + 10;
int n, x[maxn], y[maxn], w[maxn];
double ansx, ansy;
void hc() {
	for (double t = 1001; t >= 1e-8; t *= 0.9995) {
		double xx = 0.0, yy = 0.0;
		for (int i = 1; i <= n; i++) {
			double dx = x[i] - ansx, dy = y[i] - ansy;
			double dist = sqrt (dx * dx + dy * dy);
			xx += (x[i] - ansx) * w[i] / dist;
			yy += (y[i] - ansy) * w[i] / dist;
		}
		ansx += xx * t;
		ansy += yy * t;
	}
}
int main() {
	scanf ("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf ("%d %d %d", &x[i], &y[i], &w[i]);
		ansx += x[i];
		ansy += y[i];
	}
	ansx /= n;
	ansy /= n;
	hc();
	printf ("%.3lf %.3lf", ansx, ansy);
	return 0;
}

2022/11/18 00:29
加载中...