题解 | #路灯#

路灯

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;
    }
}
全部评论

相关推荐

积极的小学生不要香菜:你才沟通多少,没500不要说难
点赞 评论 收藏
分享
07-16 18:03
门头沟学院 Java
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务