模拟退火模板
需设置初始温度T0,终止温度T1,降温系数delta


以P的概率接受新答案
#define delta 0.995
int ans=0;
int cal(){...}
void sa(){
int bt=3000,et=1e-15;
while(bt>et){
...
int res=cal();
int dif=res-ans;
if(dif<=0){
ans=res;
}
else
{
if((double)exp(-dif/bt)>(double)rand()){
....
}
}
bt*=delta;
}
}
void work(){
sa();
sa();
sa();
sa();
}

浙公网安备 33010602011771号