模拟退火模板

需设置初始温度T0,终止温度T1,降温系数delta

QQ_1755337214242
QQ_1755337207804

以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();
}
posted @ 2025-08-16 17:46  Marinaco  阅读(14)  评论(0)    收藏  举报
//雪花飘落效果