cf492B Vanya and *s

时间:2023-03-09 14:25:42
cf492B Vanya and *s

B. Vanya and *s

time limit per test 1 second
memory limit per test 256 megabytes
input standard input
output standard output

Vanya walks late at night along a straight street of length l, lit by n *s. 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 * is at the point ai. The * 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 *s.

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

Input

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

The next line contains n integers ai (0 ≤ ai ≤ l). Multiple *s can be located at the same point. The *s 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 test(s)
input
7 1515 5 3 7 9 14 0
output
2.5000000000
input
2 52 5
output
2.0000000000
Note

Consider the second sample. At d = 2 the first * will light the segment [0, 4] of the street, and the second * will light segment[3, 5]. Thus, the whole street will be lit.

题意是给定x轴上n个点的x坐标,每个点可以覆盖[x-d,x+d]的区间,要求在保证覆盖[0,l]的情况下d最小

其实还是模拟……排个序就完了

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<ctime>
#define LL long long
#define inf 0x7ffffff
#define pa pair<int,int>
#define pi 3.1415926535897932384626433832795028841971
using namespace std;
inline LL read()
{
    LL x=0,f=1;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();}
    return x*f;
}
int n,l,ans;
double s;
int a[100010];
int main()
{
	n=read();l=read();
	for (int i=1;i<=n;i++)a[i]=read();
	sort(a+1,a+n+1);
	for (int i=1;i<n;i++)
	{
		ans=max(ans,a[i+1]-a[i]);
	}
	s=ans/2.0;
	if (a[1]+0.0>s)s=a[1]+0.0;
	if (l-a[n]+0.0>s)s=l-a[n]+0.0;
	printf("%.10lf",s);
}