题解 | #路灯#
路灯
http://www.nowcoder.com/practice/62cdf520b9d94616b6644ac03a0306ff
java代码
import java.text.DecimalFormat; import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { int n = sc.nextInt(); int l = sc.nextInt(); int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = sc.nextInt(); } double res = count(n, l, arr); System.out.println((new DecimalFormat("0.00").format(res))); } sc.close(); } public static double count(int n, int l, int[] arr) { Arrays.sort(arr); double res = 0.00; for (int i = 1; i < n; i++) { res = Math.max(res, ((double) (arr[i] - arr[i - 1]) / 2.0)); } res = Math.max(res, arr[0]); res = Math.max(res, l - arr[n - 1]); return res; } }