题解 | #路灯#
路灯
https://www.nowcoder.com/practice/62cdf520b9d94616b6644ac03a0306ff
#include <stdio.h> #include <stdlib.h> int cmp(int* a1,int* a2) { return *a1-*a2; } int main() { int n, l; int i=0; while(scanf("%d%d",&n,&l)==2) { int* c=malloc(n*sizeof(int)); for(i=0;i<n;i++) { scanf("%d",&c[i]); } qsort(c,n,4,cmp); int max=c[0]>(l-c[n-1])?c[0]:l-c[n-1]; int a=0; for(i=0;i<n-1;i++) { if(c[i+1]-c[i]>a) a=c[i+1]-c[i]; } float x=0.0; if(max*2>a) { x=max; printf("%.2f\n",x); } else { x=a; printf("%.2f\n",x/2); } } return 0; }