社区讨论
啊啊模拟退火56分,请帮我调一调参数,谢谢
P1337[JSOI2004] 平衡点 / 吊打XXX参与者 3已保存回复 9
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 9 条
- 当前快照
- 1 份
- 快照标识符
- @lo7ljmzb
- 此快照首次捕获于
- 2023/10/27 03:47 2 年前
- 此快照最后确认于
- 2023/10/27 03:47 2 年前
CPP
#include<bits/stdc++.h>
using namespace std;
#define PDD pair<double,double>
const int N=1e3+10;
int n;
PDD ans;
double ansnum=2e9;
struct T
{
double x,y,z;
}t[N];
double rand(double l,double r)
{
return (double)rand()/RAND_MAX*(r-l)+l;
}
double dis(PDD x,T y)
{
return sqrt((x.first-y.x)*(x.first-y.x)+(x.second-y.y)*(x.second-y.y));
}
double calc(PDD k)
{
double res=0;
for(int i=1;i<=n;i++)
{
res+=dis(k,t[i])*t[i].z;
}
if(res<ansnum)ans=k,ansnum=res;
return res;
}
void fire()
{
PDD now(rand(-1e4,1e4),rand(-1e4,1e4));
for(double T=2e4;T>=1e-6;T*=0.999)
{
PDD k(rand(now.first+T,now.first-T),rand(now.second+T,now.second-T));
double dt=calc(k)-calc(now);
if(exp(-dt/T)>rand(0,1))now=k;
}
}
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%lf%lf%lf",&t[i].x,&t[i].y,&t[i].z);
}
while((double)clock()/CLOCKS_PER_SEC<0.9)fire();//卡时
printf("%.3lf %.3lf",ans.first,ans.second);
return 0;
}
回复
共 9 条回复,欢迎继续交流。
正在加载回复...