一条长l的笔直的街道上有n个路灯,若这条街的起点为0,终点为l,第i个路灯坐标为ai,每盏灯可以覆盖到的最远距离为d,为了照明需求,所有灯的灯光必须覆盖整条街,但是为了省电,要是这个d最小,请找到这个最小的d。
2024-10-19 13:33:53
// ConsoleApplication3.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include<iostream>
#include<vector>
#include<deque>
#include<iomanip>
#include<algorithm>
using namespace std;
int main()
{
int n;
long int l;
while (cin >> n >> l)
{
vector<long int> lamps;
for (int i = 0; i < n; i++)
{
long int t;
cin >> t;
lamps.push_back(t);
}
//排序
for (int i = 0; i < n; i++)
{
for (int j = i + 1; j < n; j++)
{
if (lamps[i] > lamps[j])
{
long temp = lamps[j];
lamps[j] = lamps[i];
lamps[i] = temp;
}
}
}
double max = lamps[1] - lamps[0];
for (int i = 1; i < n - 1; i++) //找到间间距最大的
{
if (lamps[i + 1] - lamps[i]>max)
{
max = lamps[i + 1] - lamps[i];
}
}
max = max / 2;
if (l - lamps[n - 1] > max)
{
max = l - lamps[n - 1];
}
if (lamps[0] > max)
{
max = lamps[0];
}
cout << setiosflags(ios::fixed);
cout << setprecision(2) << max << endl;
}
return 0;
}
最新文章
- Kafka0.8.2.1删除topic逻辑
- HTML5学习
- 【HTML】Iframe中的onload事件
- C# Dictionary和Dynamic类型
- JavaScript的循环语句
- POSTMAN中各种请求方式的区别
- 【原】简述使用spark集群模式运行程序
- [Windows]VS2010如何以管理员权限启动?(转)
- ios调打电话代码
- 解决ubuntu合盖后无法唤醒
- 简约的返回顶部效果(jQuery)
- Android菜鸟的成长笔记(28)——Google官方对Andoird 2.x提供的ActionBar支持
- querySelector和querySelectorAll方法介绍
- 利用git下载skia库
- jpgraph 折线图--解决中文乱码的问题(标题和图例)
- jQuery中的prop()和attr()的区别
- scala调用Linux命令行
- JMeter http(s)请求插件jmeter-plugin-httpBinaryFileUpload.jar
- Kafka消费时报错:Producer connection to xxx:9092 unsuccessful
- Digispark红外接收器
热门文章
- 洛谷P2114起床困难综合征
- UVa 11234 The Largest Clique
- [LeetCode] Maximum Depth of Binary Tree dfs,深度搜索
- android基本控件学习-----SeekBar&;RatingBar
- 例说linux内核与应用数据通信系列【转】
- 查询/删除/建立DB2数据表的主键
- Codeforces Gym101473 A.Zero or One (2013-2014 ACM-ICPC Brazil Subregional Programming Contest)
- 块级元素和行内元素的区别 (block vs. inline)
- 一个项目多个App项目搭建
- EasyMvc入门教程-基本控件说明(3)时间线