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. js的意义,引用方法及变量

    一 JavaScript的意义. Javascript是浏览器端的脚本语言,它能够访问web页面的元素和运行它得浏览器,从而可以操作元素,创建新的元素等.它主要的作用有: 1.以指定尺寸.位置和样式( ...

  2. angularJS怎么实现与服务端的PHP进行数据交互

    //{params: 要传的参数obj },params这个是关键字不能换别的变量 $http.get(url, {params: {id: categoryid, key: keys} }).suc ...

  3. [ACM] POJ 1442 Black Box (堆,优先队列)

    Black Box Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7099   Accepted: 2888 Descrip ...

  4. openstack单元測试用组件一览

    声明: 本博客欢迎转发,但请保留原作者信息! 博客地址:http://blog.csdn.net/halcyonbaby 内容系本人学习.研究和总结,如有雷同,实属荣幸! 组件一览 hacking 一 ...

  5. javascript正则

      <script type="text/javascript"> //去除两边空格,如果要去除所有空格,使用/\s*即可/ String.prototype.trim ...

  6. C#(Net)软件开发常用工具汇总,提高你的开发效率

    C#(Net)软件开发常用工具汇总,提高你的开发效率 写代码也要读书,爱全栈,更爱生活.每日更新原创IT编程技术及日常实用技术文章. 我们的目标是:玩得转服务器Web开发,搞得懂移动端,电脑客户端更是 ...

  7. JavaScript随机排序算法1

    1.对数组循环,每一项与随机的某一项位置调换 <ul id="listOne"></ul> <div id="tempOne"&g ...

  8. GridView格式化数据DataFormatString

    设定BoundField的DataFormatString,通常有以下几种 DataFormatString= "{0:C}" 货币,货币的格式取决于当前Thread中Cultur ...

  9. HTML写的第一个邮箱登陆界面

    自己动手去写才会有收获,宁可模仿也不要全部复制粘贴 不说了,直接上代码.CSS有注释,适合新手. <!doctype html> <html> <head> < ...

  10. css3滚动提示

    <css揭秘>书中,滚动提示的实现 <!DOCTYPE html> <html lang="en"> <head> <meta ...