萌新求助,为什么咋调都不对啊
查看原帖
萌新求助,为什么咋调都不对啊
345750
_Oahgt楼主2020/6/9 20:32
#include <bits/stdc++.h>
#define double long double
using namespace std;
int n;
struct point{
	int x,y,w;
}a[2005];
double xs,ys,sadf=2500,ans=0x7fffffff,det=0.997;
inline double dist(double x,double y){
	double sum=0;
	for(int i=1;i<=n;++i) sum+=(sqrt((x-a[i].x)*(x-a[i].x)+(y-a[i].y)*(y-a[i].y)))*a[i].w;
	return sum;
}
inline void SA(){
	double x=xs,y=ys;
	while(sadf>1e-15){
		double X=x+((rand()*2)-RAND_MAX)*sadf;
		double Y=y+((rand()*2)-RAND_MAX)*sadf;
		double sum=dist(X,Y);
		double de=sum-ans;
		if(de<0){
			x=X;y=Y;
			xs=X;ys=Y;ans=sum;
		}
		else if(exp(-de/sadf)*RAND_MAX>rand()) x=X,y=Y;
		sadf*=det;
	}
}
int main(){
	srand(19260817);
	std::ios::sync_with_stdio(0);
	cin>>n;
	for(int i=1;i<=n;++i){
		cin>>a[i].x>>a[i].y>>a[i].w;
		xs+=a[i].x;ys+=a[i].y;
	}
	xs/=n;ys/=n;
	SA();SA();SA();SA();SA();
	cout<<setiosflags(ios::fixed)<<setprecision(3)<<xs<<' '<<ys; 
	return 0;
}

用的模拟退火, 调一周了,总是67分,#4#5#6一直WA,不知道哪里错了

2020/6/9 20:32
加载中...