using System;
using System.Collections;
using System.Collections.Generic;
public class Program {
public static void Main() {
//将路灯坐标排序,计算两两路灯之间的距离,找出最大的距离/2就是d
string line;
while ((line = System.Console.ReadLine ()) != null) { // 注意 while 处理多个 case
string[] tokens = line.Split(' ');
int n = int.Parse(tokens[0]);
int l = int.Parse(tokens[1]);
line = Console.ReadLine();
tokens = line.Split(' ');
int[] light = new int[n];
for(int i = 0; i < n; i++) light[i] = int.Parse(tokens[i]);
//冒泡排序
for(int i = 0; i < n; i++){
bool swap = false;
for(int j = 0; j < n - i - 1; j++){
if(light[j] > light[j + 1]){
int temp = light[j];
light[j] = light[j + 1];
light[j + 1] = temp;
swap = true;
}
}
if(!swap) break;
}
int[] distance = new int[n + 1];//第n和第0的索引装的是两端的灯与起点和终点的距离
for(int i = 0; i < n - 1; i++){
distance[i + 1] = light[i + 1] - light[i];
}
distance[0] = light[0];
distance[n] = l - light[n - 1];
int maxdis = 0;
for(int i = 1; i < n; i++){
if(distance[i] > maxdis) maxdis = distance[i];
}
float result = (float)maxdis / 2;
result = Math.Max(result, distance[0]);
result = Math.Max(result, distance[n]);
Console.WriteLine(result.ToString("f2"));
}
}
}
将路灯坐标排序,计算两两路灯之间的距离,找出最大的距离/2就是d,找到d后与两端路灯与起点和终点的距离s,e比较,输出d、s和e三者中的最大值

京公网安备 11010502036488号