CF_492B Vanya and Lanterns
来源:互联网 发布:软件展会 编辑:程序博客网 时间:2024/05/21 19:27
Vanya walks late at night along a straight street of length l, lit by n lanterns. Consider the coordinate system with the beginning of the street corresponding to the point 0, and its end corresponding to the point l. Then the i-th lantern is at the point ai. The lantern lights all points of the street that are at the distance of at most d from it, where d is some positive number, common for all lanterns.
Vanya wonders: what is the minimum light radius d should the lanterns have to light the whole street?
The first line contains two integers n, l (1 ≤ n ≤ 1000, 1 ≤ l ≤ 109) — the number of lanterns and the length of the street respectively.
The next line contains n integers ai (0 ≤ ai ≤ l). Multiple lanterns can be located at the same point. The lanterns may be located at the ends of the street.
Print the minimum light radius d, needed to light the whole street. The answer will be considered correct if its absolute or relative error doesn't exceed 10 - 9.
7 1515 5 3 7 9 14 0
2.5000000000
2 52 5
2.0000000000
Consider the second sample. At d = 2 the first lantern will light the segment [0, 4] of the street, and the second lantern will light segment [3, 5]. Thus, the whole street will be lit.
题意:
在一条路上放置路灯,求最小可能的路灯照射半径使整条路都等够被照亮。
题解:
很简单的一道题 ,数据量不大,简单枚举就可以A掉。从头至尾找两个路灯之间的最大的距离,是直径的长度,需要除以2,注意不要忘了两头。
代码实现:
#include <algorithm>#include <stdio.h>#include <stdlib.h>using namespace std;int a[1000];int main(){ int n,length; double dis=-1; scanf("%d%d",&n,&length); for(int i=0;i<n;i++) scanf("%d",&a[i]); sort(a,a+n); for(int i=1;i<n;i++) { dis=max(dis,(double)a[i]-a[i-1]); } dis/=2; dis=max(dis,(double)a[0]-0); dis=max(dis,(double)length-a[n-1]); printf("%.10lf",dis); return 0;}
- CF_492B Vanya and Lanterns
- Vanya and Lanterns
- B. Vanya and Lanterns
- B - Vanya and Lanterns
- B - Vanya and Lanterns
- Vanya and Lanterns
- codeforces Vanya and Lanterns
- Codeforces Vanya and Lanterns
- 492B - Vanya and Lanterns
- codeforce492 B. Vanya and Lanterns
- Codefroces 280 div2 B. Vanya and Lanterns
- Codeforces 492B. Vanya and Lanterns 二分
- Codeforces 492B Vanya and Lanterns(水)
- coderforce 492B Vanya and Lanterns
- CF 280B. Vanya and Lanterns(div2)
- Codeforces-492B-Vanya and Lanterns
- Codeforces 492B Vanya and Lanterns【贪心】
- Codeforces Round 280 Div2 B Vanya and Lanterns(binary serch)
- Microsoft Office 2003+2007+2010+2013 办公软件合集(带永久激活工具)
- 贡献gulp插件两枚
- IDL设置数组的中的nodata值
- JAVA笔记:异常的基本概念
- 身体就是财富
- CF_492B Vanya and Lanterns
- 数据结构思维导图——第四章:字符串和多维数组
- 2015年了
- (30 hackdays day 14) Muse - 了解自己
- 求最大连续递增数字串(如“ads3sl456789DF3456ld345AA”中的“456789”)
- OpenCV 图像增强—直方图均衡化和灰度拉伸
- 搞笑 游戏画面
- CSS3伪类target
- HDU 4109 Instrction Arrangement