Vanya and Lanterns

Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description

Vanya walks late at night along a straight street of length l, lit by n lanterns. Consider the coordinate system with the beginning of the street corresponding to the point 0, and its end corresponding to the point l. Then the i-th lantern is at the point ai. The lantern lights all points of the street that are at the distance of at most d from it, where d is some positive number, common for all lanterns.

Vanya wonders: what is the minimum light radius d should the lanterns have to light the whole street?

Input

The first line contains two integers n, l (1 ≤ n ≤ 1000, 1 ≤ l ≤ 109) — the number of lanterns and the length of the street respectively.

The next line contains n integers ai (0 ≤ ai ≤ l). Multiple lanterns can be located at the same point. The lanterns may be located at the ends of the street.

Output

Print the minimum light radius d, needed to light the whole street. The answer will be considered correct if its absolute or relative error doesn't exceed 10 - 9.

Sample Input

Input
7 15
15 5 3 7 9 14 0
Output
2.5000000000
Input
2 5
2 5
Output
2.0000000000
 
    
题意:

n个路灯,分布在L长的街上,整点坐标。计算路灯最小的照明范围,使整条街都能有光。

解题思路:先把路灯位置排序(快速排序算法),然后计算相邻路灯距离的一半的最大值,第一个路灯与起始点的距离,最后一个路灯与尽头之间的距离,三者取最大值。

#include <stdio.h>
#include<string.h>
int b[1005];
void fast_sort(int a[],int low,int high)
{
    int i=low;
    int j=high;
    int t=a[i];
    if(low<high)
    {
        while(i<j)
        {
            while((a[j]>=t)&&i<j)
                j--;
            a[i]=a[j];
            while((a[i]<=t)&&i<j)
                i++;
            a[j]=a[i];

        }
        a[i]=t;
        fast_sort(a,low,i-1);
        fast_sort(a,j+1,high);
    }
    else
    {
        return;
    }
}
int main()
{
    int n,l;
    int i;
    double d;
    scanf("%d%d",&n,&l);
    for(i=0;i<n;i++)
    {
        scanf("%d",&b[i]);
    }
    fast_sort(b,0,n-1);
    d=b[0]>(l-b[n-1])?b[0]:(l-b[n-1]);
    for( i=1;i<n;i++)
    {
        d=d>((b[i]-b[i-1])/2.0)?d:((b[i]-b[i-1])/2.0);
    }
    printf("%.10lf\n",d);

    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值