救救退火的孩子
查看原帖
救救退火的孩子
100325
peterwuyihong楼主2020/12/31 17:42
#include<bits/stdc++.h>
using namespace std;
#define debug(x) cerr<<#x<<' '<<x<<endl
#ifndef ONLINE_JUDGE
	#define fuck getchar
#else
	#define fuck nc
#endif
char nc(){
  	static char buf[1<<25],*p=buf,*q=buf;
  	if(p==q&&(q=(p=buf)+fread(buf,1,1<<25,stdin),p==q))return EOF;
  	return *p++;
}
template<class T>void read(T&x){
	short f=1;x=0;
	char ch=fuck();
	while(!isdigit(ch)){
		if(ch=='-')f=-1;
		ch=fuck();
	}while(isdigit(ch)){
		x=(x<<1)+(x<<3)+(ch^48);
		ch=fuck();
	}x*=f;
}
template<class T>void write(T x){
	if(x<0)putchar('-'),x=-x;
	if(x>=10)write(x/10);
	putchar(x%10+48);
}

#define maxn 5010
int n;
int l,r;
int a[maxn];
int m[1000010];
int check(int x){
	for(int i=1;i<=n;i++)m[a[i]%x]++;
	int ret=0;
	for(int i=1;i<=n;i++)
	if(m[a[i]%x]>1)ret+=m[a[i]%x]-1;
	for(int i=1;i<=n;i++)m[a[i]%x]=0;
	return ret;
}
double Rand(){
	return (double)rand()/RAND_MAX;
}
int randint(int l,int r){
	return rand()*rand()%(r-l+1)+l;
}
void SA(){
	double T=1000;
	int now=(l+r)>>1; 
	for(;T>1e-3;T*=0.94){
		int x=(1ll*now+rand()%100-50+1000*(r-l+1))%(r-l+1)+n;
		int delta=check(x);
		if(delta==0)now=x,r=min(r,x);
		else if(exp(-delta/T)<Rand())now=x;
	}
}
signed main(){
	srand(time(NULL));
#ifndef ONLINE_JUDGE
	freopen("testdata.in","r",stdin);
#endif
	read(n);
	for(int i=1;i<=n;i++)read(a[i]);
	sort(a+1,a+n+1);
	l=n,r=a[n];
	while((double)clock()/CLOCKS_PER_SEC<=0.4)SA();
	cout<<r<<endl;
}

(数据再水一点就是退火好题了,害

(也可能是我太菜

(但我真觉得调不出来参了

2020/12/31 17:42
加载中...