路灯照明 [(https://www.online1987.com/路灯照明/)]
#include<iostream>
#include<climits>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
int maxValue = 0;
int n = 0;
int l = 0;
cin >> n >> l;
vector<int> nums(n+1, 0);//vector只有初始化的元素可以赋值,如果vector不初始化,默认大小为0,对nums[i]赋值会报错.
for (int i = 0; i<n&&cin >> nums[i]; ++i) {
;
}
sort(nums.begin(), nums.end());
for (int i = 0; i < n; ++i) {
if (i == n - 1) maxValue = max(l - nums[i + 1], maxValue);
maxValue = max(nums[i + 1] - nums[i], maxValue);
}
cout<<(double)maxValue / 2<<endl;
return 0;
}
标签:路灯,nums,int,maxValue,vector,照明,include
From: https://www.cnblogs.com/chunbai11/p/16744658.html