萌新90求助,#5wa
查看原帖
萌新90求助,#5wa
225703
jyz666楼主2020/8/8 21:14
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
#include<iostream>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
#define maxn 5000010
#define inf 0x3f3f3f3f
const int mod=100003;

void read(ll &x){
	int f=1;x=0;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') {x=x*10+ch-'0';ch=getchar();}
	x*=f;
}
ll n,a[maxn];
db pos[maxn],f[maxn],g[maxn];
int main(){
	read(n);
	for(int i=1;i<=n;i++){
		ll x;read(x);
		pos[i]=1.0*x;
	}
	sort(pos+1,pos+n+1);
	if(n==1){
		cout<<0<<endl;
		return 0;
	}
	if(n==2){
		cout<<pos[2]-pos[1]<<endl;return 0;
	}
	f[2]=pos[2]-pos[1];
	int head=1,tail=0;
	a[++tail]=2;
	for(int i=3;i<=n;i++){
		while(max(pos[i]-pos[a[head]],f[a[head]]+1.0)>max(pos[i]-pos[a[head+1]],f[a[head+1]]+1.0)){
			if(head==tail)break;
			head++;
		}
		f[i]=max(pos[i]-pos[a[head]],f[a[head]]+1.0);
		while(f[i]<f[a[tail]]){
			tail--;
			if(tail<head)break;
		}
		a[++tail]=i;
	}
	g[n-1]=pos[n]-pos[n-1];
	memset(a,0,sizeof(a));
	head=tail=1;
	a[tail]=n-1;
	double ans=(0x3f3f3f3f3f)*1.0;
	for(int i=n-2;i>=1;i--){
		while(max(pos[a[head]]-pos[i],g[a[head]]+1)>max(pos[a[head+1]]-pos[i],g[a[head+1]]+1)){
			if(head==tail)break;
			head++;
		} 
		g[i]=max(pos[a[head]]-pos[i],g[a[head]]+1);
		while(g[i]<g[a[tail]]){
			tail--;
			if(tail<head)break;
		}
		a[++tail]=i;
	} 
	for(int i=1;i<=n;i++){
		ans=min(max(f[i]*1.0,g[i]*1.0),ans);
		if(i>1){
			ans=min(max((pos[i]-pos[i-1])*1.0/2,max(f[i-1]*1.0+1,g[i]*1.0+1)),ans);
		}	
	}
	printf("%.1lf",ans);
	return 0;
}
2020/8/8 21:14
加载中...