比赛 4043级NOIP2022欢乐赛7th 评测结果 C
题目名称 愤怒的奶牛 最终得分 0
用户昵称 ZRQ 运行时间 0.000 s
代码语言 C++ 内存使用 0.00 MiB
提交时间 2022-11-20 11:33:28
显示代码纯文本
#include<bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
using namespace std;
const int N=550000;
int n;
double l[N],r[N];
double a[N];
void pre()
{
  l[1]=0;
  for(int i=2;i<=n;i++)
  {
    l[i]=inf;
    int low=1,high=i;
    while(low+1<high)
    {
      int mid=(low+high)/2;
      if(l[mid-1]+1<a[i]-a[mid-1]) low=mid;
      else high=mid;
    }
    l[i]=min(max(a[i]-a[low-1],l[low-1]+1),max(a[i]-a[high-1],l[high-1]+1));
  }
  r[n]=0;
  for(int i=n-1;i>=1;i--)
  {
    r[i]=inf;
    int low=i,high=n;
    while(low+1<high)
    {
      int mid=(low+high)/2;
      if(r[mid+1]+1<a[mid+1]-a[i]) high=mid;
      else low=mid;
    }
    r[i]=min(max(a[low+1]-a[i],r[low+1]+1),max(a[high+1]-a[i],r[high+1]+1));
  }
}
bool ifok(double x)
{
  for(int i=n;i>=1;i--)
  {
    if(l[i]+1<=x)
    {
      for(int j=1;j<=n&&a[j]<=a[i]+2*x;j++)
      {
        if(r[j]+1<=x) return true;
      }
      break;
    }
  }
  return false;
}
int main()
{
  freopen("angry.in","r",stdin);
  freopen("angry.out","w",stdout)
  scanf("%d",&n);
  for(int i=1;i<=n;i++)
  {
    scanf("%lf",&a[i]);
  }
  sort(a+1,a+1+n);
  pre();
  double low=1,high=a[n];
  while(high-low>0.01)
  {
    double mid=(low+high)/2;
    if(ifok(mid)) high=mid;
    else low=mid;
  }
  printf("%.1f\n",low);
  return 0;
}