求调:是参数的问题吗,还是码有问题(应该是码
查看原帖
求调:是参数的问题吗,还是码有问题(应该是码
733734
yanxu_cn楼主2024/10/14 20:54

rt

code:

#include<bits/stdc++.h>
using namespace std;
int n;
constexpr double tmax=2000,tmin=1e-10,tlower=.97;
class point
{
	public:
	long double x0,y0;
	int w;
	inline const long double dist(const point p)const
	{
		return sqrt(powl(x0-p.x0,2)+powl(y0-p.y0,2))*p.w*w;
	}
}pt[1007],bestp=point{-10001,-10001,1};
inline long double compute(point p)
{
	long double ans=0;
	for(int i=0;i<n;i++)
	{
		ans+=p.dist(pt[i]);
	}
	return ans;
}
inline long double dmkr(int r)
{
	unsigned int rs=abs(r);
	long double rsr=(long double)rs/INT_MAX*20000-10000;
	return rsr;
}
void sa(int rand_seed)
{
	mt19937_64 mtr(rand_seed);
	for(double t=tmax;t>tmin;t*=tlower)
	{
		point p=point{dmkr(mtr()),dmkr(mtr()),1};
		long double res=compute(p),rbestp=compute(bestp);
		if(res<rbestp)rbestp=res,bestp=p;
		else if(exp((res-rbestp)/t)*INT_MAX*5<abs((int)mtr()))
		bestp=p;
	}
}
void solve()
{
	mt19937 mt(time(0));
	while(clock()<2*CLOCKS_PER_SEC)sa(mt());
}
int main()
{
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>pt[i].x0>>pt[i].y0>>pt[i].w;
	}
	solve();
	printf("%.3f %.3f",(float)bestp.x0,(float)bestp.y0);
	return 0;
}
2024/10/14 20:54
加载中...