题意

题目链接

求 $F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x (0 <= x <=100)$的最小值

Sol

强上模拟退火,注意eps要开大!

/*
*/
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
using namespace std;
const int MAXN = 1e6 + ;
const double eps = 1e-, Dlt = 0.98;
int T;
double Y, Best;
double F(double x) {
return * x * x * x * x * x * x * x + * x * x * x * x * x * x + * x * x * x + * x * x - Y * x;
}
double getrand(double T) {
return T * ((rand() << ) - RAND_MAX);
}
double solve(int id) {
double x = id, now = F(x);
Best = min(Best, now);
for(double T = ; T > eps; T *= Dlt) {
double wx = x + getrand(T), wv = F(wx);
if(wx > eps && (wx - <= 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 = ;
while(times--) solve(times);
printf("%.4lf\n", Best);
}
return ;
}
/*
3
100
200
1000000000
*/
05-26 19:38