思路:SA + 卡时
样例过了,测试点一个过不去
帮忙调一下参数,应该是参数的问题
问一下SA的参数一般设什么比较好,考场上有什么好用的技巧
#include<bits/stdc++.h>
#define int long long
using namespace std;
const double step = 2e4;
struct node{
double arr[11];
}point[114514];
int n; node ans;double ansn = 1e18;
double square_dirta(node a, node b) {
double sum = 0;
for(int i=1; i<=n; ++i) {
sum += (a.arr[i]-b.arr[i])*(a.arr[i]-b.arr[i]);
}
return sqrt(sum);
}
double calc(node index) {
double sum = 0;
for(int i=1; i<=n+1; ++i) {
sum += square_dirta(index, point[i]);
}
sum /= (n+1);
double tempsum = 0;
for(int i=1; i<=n+1; ++i) {
tempsum += (sum - square_dirta(index, point[i])) * (sum - square_dirta(index, point[i]));
}
if(ansn > tempsum) {
ansn = tempsum;
ans = index;
}
return sqrt(tempsum);
}
double Rand(double l, double r) {
return ((double)(rand())/RAND_MAX) * (r-l+1) + l;
}
node first;
node Random(double t) {
node temp;
for(int i=1; i<=n; ++i) {
temp.arr[i] = Rand(first.arr[i]-t, first.arr[i]+t);
}
return temp;
}
void simulate_anneal() {
node now = first;
for(double t = 10000; t >= 0.0000001; t *= 0.9999) {
node to = Random(t); double dt = calc(to) - calc(now);
if(dt < 0) {
now = to;
}
if(exp(double(-dt/t)) > Rand(0, 1)) {
now = to;
}
}
}
signed main() {
cin >> n;
for(int i=1; i<=n; ++i) {
first.arr[i] = 0;
}
for(int i=1; i<=n+1; ++i) {
for(int j=1; j<=n; ++j) {
cin >> point[i].arr[j];
first.arr[j] += point[i].arr[j];
}
}
while(double(clock()) / CLOCKS_PER_SEC <= 0.56) {
simulate_anneal();
}
for(int i=1; i<=n; ++i) {
printf("%.3lf ", ans.arr[i]);
}
return 0;
}