算法-初次尝试-模拟退火
2021/4/18 20:25:16
本文主要是介绍算法-初次尝试-模拟退火,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
我对模拟退火的初步理解,还没深入了解过。这里只是用模拟退火求函数极值。
题目:https://vjudge.net/problem/HDU-2899
#include<bits/stdc++.h> using namespace std; #define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); typedef long long ll; typedef unsigned long long ull; const ll MAXN=1e18; const double eps=1e-8; double y; double func(double x){ return 6*x*x*x*x*x*x*x+8*x*x*x*x*x*x+7*x*x*x+5*x*x-y*x; } int f[2]={-1,1}; int main(){ srand(time(NULL)); int t; cin>>t; while(t--){ cin>>y; double T=100; double delta=0.98; double x=50; double ans=func(x); while(T>eps){ int f[2]={-1,1}; double newx=x+f[rand()%2]*T; if(newx>=0&&newx<=100){ double next=func(newx); if(ans>next){ ans=next; x=newx; } } T*=delta; } cout<<fixed<<setprecision(4)<<ans<<'\n'; } return 0; }
这篇关于算法-初次尝试-模拟退火的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-15鸿蒙生态设备数量超8亿台
- 2024-05-13TiDB + ES:转转业财系统亿级数据存储优化实践
- 2024-05-09“2024鸿蒙零基础快速实战-仿抖音App开发(ArkTS版)”实战课程已上线
- 2024-05-09聊聊如何通过arthas-tunnel-server来远程管理所有需要arthas监控的应用
- 2024-05-09log4j2这么配就对了
- 2024-05-09nginx修改Content-Type
- 2024-05-09Redis多数据源,看这篇就够了
- 2024-05-09Google Chrome驱动程序 124.0.6367.62(正式版本)去哪下载?
- 2024-05-09有没有大佬知道这种数据应该怎么抓取呀?
- 2024-05-09这种运行结果里的10.100000001,怎么能最快改成10.1?