B. Vanya and Lanterns

time limit per test 1 second
memory limit per test 256 megabytes
input standard input
output standard output

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?

Input

The first line contains two integers nl (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.

Output

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.

Sample test(s)
input
7 1515 5 3 7 9 14 0
output
2.5000000000
input
2 52 5
output
2.0000000000
Note

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.

题意是给定x轴上n个点的x坐标,每个点可以覆盖[x-d,x+d]的区间,要求在保证覆盖[0,l]的情况下d最小

其实还是模拟……排个序就完了

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<ctime>
#define LL long long
#define inf 0x7ffffff
#define pa pair<int,int>
#define pi 3.1415926535897932384626433832795028841971
using namespace std;
inline LL read()
{
    LL x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n,l,ans;
double s;
int a[100010];
int main()
{
	n=read();l=read();
	for (int i=1;i<=n;i++)a[i]=read();
	sort(a+1,a+n+1);
	for (int i=1;i<n;i++)
	{
		ans=max(ans,a[i+1]-a[i]);
	}
	s=ans/2.0;
	if (a[1]+0.0>s)s=a[1]+0.0;
	if (l-a[n]+0.0>s)s=l-a[n]+0.0;
	printf("%.10lf",s);
}

cf492B Vanya and Lanterns的更多相关文章

  1. Codeforces 492B B. Vanya and Lanterns

    Codeforces  492B   B. Vanya and Lanterns 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid= ...

  2. Vanya and Lanterns

    Description Vanya walks late at night along a straight street of length l, lit by n lanterns. Consid ...

  3. codeforces 492B. Vanya and Lanterns 解题报告

    题目链接:http://codeforces.com/problemset/problem/492/B #include <cstdio> #include <cstdlib> ...

  4. Codeforces Round #280 (Div. 2) A B C 暴力 水 贪心

    A. Vanya and Cubes time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  5. CodeForces Round #280 (Div.2)

    A. Vanya and Cubes 题意: 给你n个小方块,现在要搭一个金字塔,金字塔的第i层需要 个小方块,问这n个方块最多搭几层金字塔. 分析: 根据求和公式,有,按照规律直接加就行,直到超过n ...

  6. Codeforces Round #280 (Div. 2) A , B , C

    A. Vanya and Cubes time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  7. [codeforces] 暑期训练之打卡题(一)

    每个标题都做了题目原网址的超链接 Day1<Vanya and Lanterns> 题意: 一条长度为 l 的街道,在这条街道上放置了n个相同的灯,街道一端位置记为0,每个灯的位置在ai处 ...

  8. Lanterns

    Lanterns 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=86640#problem/B 题目: Description ...

  9. codeforces C. Vanya and Scales

    C. Vanya and Scales Vanya has a scales for weighing loads and weights of masses w0, w1, w2, ..., w10 ...

随机推荐

  1. [置顶] 如何更改CSDN博客高亮代码皮肤的样式,使博客看起来更有范(推荐)

    由于本人写博客的时候,也没有配置博客的相关属性,因此贴出来的代码块都是CSDN默认的,因此代码背景色都是白色的,如下所示: 但是本人在浏览他人博客的时候,发现有些博客的代码块看起来比较有范,整个代码库 ...

  2. 关于C/C++函数指针声明的理解

    [前言] 由于最近对函数指针的理解比较模糊,所有又重新学习了一把关于函数指针的知识,参考了很多书籍和网上的文章.现在本人进行一下分享和总结.本文的其实只是整理和总结别人现有的文章,作为备用参考文档. ...

  3. 日期函数(SqlServer)

    1.常用日期方法(下面的GetDate() = '2006-11-08 13:37:56.233') (1)DATENAME ( datepart ,date ) 返回表示指定日期的指定日期部分的字符 ...

  4. JAXB--学习2

    一.Jaxb处理java对象和xml之间转换常用的annotation有: @XmlType @XmlElement @XmlRootElement @XmlAttribute @XmlAccesso ...

  5. 关于使用mybatis插件自动生成代码

    1.安装 mybatis 插件: 在 eclipse 中 点击 help-->Install New Software...--> Add --> local  选择插件中eclip ...

  6. CoDel Test Script

    This TCL script is retrieved from http://www.pollere.net/CoDel.html in November 2013 :) # Codel test ...

  7. Node.js 实现简单小说爬虫

    最近因为剧荒,老大追了爱奇艺的一部网剧,由丁墨的同名小说<美人为馅>改编,目前已经放出两季,虽然整部剧槽点满满,但是老大看得不亦乐乎,并且在看完第二季之后跟我要小说资源,直接要奔原著去看结 ...

  8. Android Studio设置Eclipse风格快捷键

    Android Studio的1.1.0版本都发布了,ADT也不会再更新了,童鞋们还有理由不换嘛,不要死守着Eclipse了,Android Studio是你唯一的也是最好的选择.什么?用Eclips ...

  9. (转)跟我一起学JQuery插件开发教程

    在逛codeproject网站的时候,突然看到一篇文章:How to write plugin in Jquery. 如果对E文好的同学 ,可以看上面的连接.现在我把上面网站的及结合自己的想法写这篇文 ...

  10. DOM不同的结点类型

    1)node类型 nodeName(what node) and nodeValue(always null) node父子之间可以用childNodes来表示 firstChild,childNod ...