Program B--codeforces 492B

Source: Internet
Author: User

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 are at the point aI. The lantern lights All points of the street is at the

Distance of In most D from it, where D was some positive number, common for all lanterns.

Vanya Wonders:what is the minimum light radius D Should the lanterns has to light the whole street?

Input

The first line contains the 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≤ ail). Multiple lanterns can is located at the same point. The lanterns is located at the ends of the street.

Output

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

Sample Input

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




The main idea: Vanya walk in a long street, the street has n lights, this n can be in the random position on L, so the radius of light irradiation are the same, the minimum radius of the lamp to make the whole street has light.

Note: Any two lights must be adjacent.

Analysis: This problem can be solved directly with violence, but pay attention to two points. First, the n lamp includes the left and right two endpoints, so long as the two lamps are known to be the maximum distance (in sum),

Half of it is the minimum radius required;

If only one or two endpoints are included, the distance from the left end to the first light (in C) is compared to the last lamp to the right end (denoted by D),

Take a larger value to C, because C itself is the radius, so if C is twice times greater than or equal to the maximum distance of the two lights, output C, otherwise output sum of half.




The code is as follows:



#include<iostream>#include<cstdio>#include<algorithm>UsingNamespace Std;IntMain(){int n, lA[1005],cPQ, flag, ID;Double sum;While(scanf("%d%d", &n, &l)==2){C=0D=0P=0Q=0, Sum=0.0, flag=0;For(I=0; I<n; I++)scanf("%d", &a[I]);Sort(AA+n);For(I=0; I<n&&a[I]<=l; I++){If(A[0]==0&&a[n-1]==l) flag=1; Q=a[I]-p; P=a[I];If(q>=sum) sum=q;}If(!flag){If(A[0]!=0) c=a[0];If(A[n-1]!=l) d=l-A[n-1]; C=Max(cD);If(2*c>=sum)Printf("%.10LF\ n",(Double); else printf ( "%.10lf\n" ,sum /2);  else printf  ( "%.10lf\n  ",sum/2 return 0;< Span class= "Sh-cbracket" >             

Program B--codeforces 492B

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.