求大佬看看无参数之外的问题。
不管怎么调参,一直在90pts左右。
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<ctime>
using namespace std;
const int maxn=55;
const int delta=0.888;
int n,m,c,p[maxn],cnt,ans,ma[maxn][maxn],anss[maxn][maxn],lans;
int cal(int x1,int x2,int y1,int y2){
int ans=0;
if(x1>1) ans+=(ma[x1][y1]==ma[x1-1][y1])-(ma[x2][y2]==ma[x1-1][y1]);
if(x1<n) ans+=(ma[x1][y1]==ma[x1+1][y1])-(ma[x2][y2]==ma[x1+1][y1]);
if(y1>1) ans+=(ma[x1][y1]==ma[x1][y1-1])-(ma[x2][y2]==ma[x1][y1-1]);
if(y1<m) ans+=(ma[x1][y1]==ma[x1][y1+1])-(ma[x2][y2]==ma[x1][y1+1]);
if(x2>1) ans-=(ma[x1][y1]==ma[x2-1][y2])-(ma[x2][y2]==ma[x2-1][y2]);
if(x2<n) ans-=(ma[x1][y1]==ma[x2+1][y2])-(ma[x2][y2]==ma[x2+1][y2]);
if(y2>1) ans-=(ma[x1][y1]==ma[x2][y2-1])-(ma[x2][y2]==ma[x2][y2-1]);
if(y2<m) ans-=(ma[x1][y1]==ma[x2][y2+1])-(ma[x2][y2]==ma[x2][y2+1]);
return ans;
}
void gx(){
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
anss[i][j]=ma[i][j];
}
}
}
void SA(){
double t=1000;
while(t>0.1){
if(lans-ans>t*300){
lans=ans;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
ma[i][j]=anss[i][j];
}
}
}
int x1=rand()%n+1,x2=rand()%n+1,y1=rand()%m+1,y2=rand()%m+1;
if(ma[x1][y1]==ma[x2][y2]) continue;
int res=cal(x1,x2,y1,y2);
if(res<0){
swap(ma[x1][y1],ma[x2][y2]);
lans+=res;
if(lans<ans) ans=lans,gx();
}
else{
if(exp(-res/t)*RAND_MAX>rand()) lans+=res,swap(ma[x1][y1],ma[x2][y2]);
}
t*=delta;
}
for(int i=1;i<=2000;i++){
if(lans-ans>t*300){
lans=ans;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
ma[i][j]=anss[i][j];
}
}
}
int x1=rand()%n+1,x2=rand()%n+1,y1=rand()%m+1,y2=rand()%m+1;
if(ma[x1][y1]==ma[x2][y2]) continue;
int res=cal(x1,x2,y1,y2);
if(res<0){
swap(ma[x1][y1],ma[x2][y2]);
lans+=res;
if(lans<ans) ans=lans,gx();
}
else{
if(exp(-res/t)*RAND_MAX>rand()) lans+=res,swap(ma[x1][y1],ma[x2][y2]);
}
}
}
int main(){
srand(time(NULL));
srand(rand());
srand(rand());
ios::sync_with_stdio(false);
cin>>n>>m>>c;
for(int i=1;i<=c;i++){
cin>>p[i];
}
int now=1,noww=1;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(p[now]<noww) now++,noww=1;
ma[i][j]=now;
noww++;
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(i!=n) ans+=ma[i][j]!=ma[i+1][j];
if(j!=m) ans+=ma[i][j]!=ma[i][j+1];
}
}
gx();
lans=ans;
while((double)clock()/CLOCKS_PER_SEC<4.8){
SA();
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cout<<anss[i][j]<<" ";
}
cout<<endl;
}
return 0;
}