比赛 |
4043级NOIP2022欢乐赛7th |
评测结果 |
AAAAAAAAAA |
题目名称 |
愤怒的奶牛 |
最终得分 |
100 |
用户昵称 |
op_组撒头屯 |
运行时间 |
0.030 s |
代码语言 |
C++ |
内存使用 |
4.35 MiB |
提交时间 |
2022-11-20 09:32:00 |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=50000+5;
const double eps=1e-3;
int n;
ll x[N],b[N];
ll lmn[N],rmn[N];
bool check(double mid){
for (int i=n;i>=1;i--){
if (1.0*lmn[i]<=mid-1){
int l=upper_bound(x+i+1,x+n+1,1.0*x[i]+2.0*mid)-x-1;
if (1.0*rmn[l]<=mid-1)return 1;
else return 0;
}
}
return 0;
}
int main(){
freopen ("angry.in","r",stdin);
freopen ("angry.out","w",stdout);
scanf("%d",&n);
for (int i=1;i<=n;i++)scanf("%lld",&x[i]);
sort(x+1,x+n+1);
memset(lmn,0x3f,sizeof(lmn));
lmn[1]=0;b[1]=lmn[1]+1+x[1];
for (int i=2;i<=n;i++){
int l=lower_bound(b+1,b+i,x[i])-b;
lmn[i]=min(max(lmn[l-1]+1,x[i]-x[l-1]),max(lmn[l]+1,x[i]-x[l]));
b[i]=lmn[i]+1+x[i];
}
memset(rmn,0x3f,sizeof(rmn));
rmn[n]=0;b[n]=x[n]-rmn[n]-1;
for (int i=n-1;i>=1;i--){
int l=lower_bound(b+i+1,b+n+1,x[i])-b;
rmn[i]=min(max(rmn[l-1]+1,x[l-1]-x[i]),max(rmn[l]+1,x[l]-x[i]));
b[i]=x[i]-rmn[i]-1;
}
double l=1,r=x[n]-x[1];
while(fabs(l-r)>eps){
double mid=(l+r)/2;
if (check(mid))r=mid;
else l=mid;
}
printf("%.1lf\n",l);
return 0;
}