温度太高
by panda_2134 @ 2018-05-21 20:21:27
一般的话取 $t_{\text{start}} = 100, t_{\text{end}} = 10^{-8}, \Delta = 0.98$ 就可以了……
其实还有一种从多个点同时开始退火的操作……可能会更快一些达到最优解? 这个操作可以看这个:[模拟退火算法](https://blog.csdn.net/google19890102/article/details/45395257) 代码虽然是java但是也很好懂,主要是这个人参数调的好2333
by panda_2134 @ 2018-05-21 20:24:25
这个题要取 $t_{\text{start}} = 5 \times 10^5 \dots$
by panda_2134 @ 2018-05-21 20:29:23
然后$t_{\text{end}} = 10^{-5}\dots$
by panda_2134 @ 2018-05-21 20:29:50
```cpp
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#include<time.h>
#include<iostream>
#include<queue>
#include<stack>
#include<map>
#include<cmath>
#define ll long long
#define oo 0x7fffffff
using namespace std;
int read()
{
int out=0,fh=1;
char cc=getchar();
while ((cc>'9'||cc<'0')&&cc!='-')
cc=getchar();
if (cc=='-')
{
fh=-1;
cc=getchar();
}
while (cc>='0'&&cc<='9')
{
out=out*10+cc-'0';
cc=getchar();
}
return out*fh;
}
const int MAXN=1e3+10;
struct node{
double x,y;
double g;
node(double x=0,double y=0)
{
this->x=x;
this->y=y;
}
}A[2*MAXN];
int n;
node ans;
double dis(node a,node b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
double calc(node root)
{
double sans=0;
for(int i=1;i<=n;++i)
sans+=dis(root,A[i])*A[i].g;
return sans;
}
double Rand()//[0,1]
{
return double(rand()/double(RAND_MAX));
}
bool AC(double delta,double T)
{
return ((delta<0) || (Rand() < exp(-delta/T)));
}
node SA(node initAns,int initT,double dt,double minT)
{
double T=initT;
node Now=initAns;
double NowAns=calc(Now);
while(T>minT)
{
node Next=(Now.x+T*(rand()*2-RAND_MAX),Now.y+T*(rand()*2-RAND_MAX));
double NextAns=calc(Next);
double delta=NextAns-NowAns;
if(AC(delta,T))
{
Now=Next;
NowAns=NextAns;
}
T*=dt;
}
return Now;
}
int main()
{
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
srand((int)time(NULL));
n=read();
node init;
for(int i=1;i<=n;++i)
{
scanf("%lf%lf%lf",&A[i].x,&A[i].y,&A[i].g);
init.x+=A[i].x;
init.y+=A[i].y;
}
init.x/=double(n),init.y/=double(n);
node ycfm=SA(init,200,0.998,1e-15);
printf("%.3lf %.3lf",ycfm.x,ycfm.y);
//fclose(stdin);
//fclose(stdout);
return 0;
}
```
by jklover @ 2018-08-12 12:43:14
帮我也看看,我也过不了样例
by jklover @ 2018-08-12 12:43:40