丹田呼吸法,江油二手房,胶卷儿别跑
求 $f(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x (0 <= x <=100)$的最小值
强上模拟退火,注意eps要开大!
/* */ #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> #include<ctime> using namespace std; const int maxn = 1e6 + 10; const double eps = 1e-10, dlt = 0.98; int t; double y, best; double f(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; } double getrand(double t) { return t * ((rand() << 1) - rand_max); } double solve(int id) { double x = id, now = f(x); best = min(best, now); for(double t = 101; t > eps; t *= dlt) { double wx = x + getrand(t), wv = f(wx); if(wx > eps && (wx - 100 <= eps)) { if(wv < best) x = wx, best = wv, now = wv; if(wv < now || ((exp((wv - now) / t)) * rand_max < rand())) now = wv, x = wx; } } } int main() { srand((unsigned)time(null)); scanf("%d", &t); while(t--) { best = 1e20; scanf("%lf", &y); int times = 100; while(times--) solve(times); printf("%.4lf\n", best); } return 0; } /* 3 100 200 1000000000 */
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
如何在没有core文件的情况下用dmesg+addr2line定位段错误
用QT制作3D点云显示器——QtDataVisualization
网友评论