「CF492B」Vanya and Lanterns
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?
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.
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.
1 2 |
7 15 15 5 3 7 9 14 0 |
1 |
2.5000000000 |
1 2 |
2 5 2 5 |
1 |
2.0000000000 |
Consider the second sample. At d = 2 the first lantern will light the segment [0, 4] of the street, and the second lantern will light segment [3, 5]. Thus, the whole street will be lit.
题解
显然选取max{a[1],l-a[n],(a[i]-a[i]-1)/2}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
#include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<map> #include<ctime> #include<vector> #include<set> #include<cmath> #include<algorithm> #define inf 1000000000 #define ll long long #define pa pair<int,int> using namespace std; int read() { int 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; double a[1005],ans; int main() { n=read();l=read(); for(int i=1;i<=n;i++)a[i]=read(); sort(a+1,a+n+1); ans=max(a[1],l-a[n]); for(int i=2;i<=n;i++) ans=max(ans,(a[i]-a[i-1])/2); printf("%.10lf",ans); return 0; } |