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. 《图解HTTP》 第11章 web的攻击技术

    11.1 针对Web的攻击技术 简单的HTTP协议本身并不存在安全性问题,所以协议本身几乎不会成为攻击的对象. 11.1.1 HTTP不具备必要的安全功能 11.1.2 在客户端即可篡改请求 在HTT ...

  2. JDBC编程之优化

    1.创建 dbconfig.properties driver=com.mysql.jdbc.Driver dburl=jdbc\:mysql\://localhost\:3306/mytest us ...

  3. MySQL日期函数

    1.已知出生日期,求年龄 SELECT '1992-04-10' as birthday, curdate(), ( YEAR (curdate()) - YEAR ('1992-04-10')-1 ...

  4. (转)苹果消息推送服务器 php 证书生成

    1.准备好 aps_developer_identity.cer , push.p12这两个证书文件 2. 生成证书如下: openssl x509 -in aps_developer_identit ...

  5. android中发送邮件

    在移动互联网时代,手机邮件已不是什么新鲜事了,我们可以使用内置的Gmail引擎来发送邮件,也可以使用SMTP来发送邮件,下面用一个简单示例来演示邮件的发送,包括单方发送邮件.多方发送邮件以及抄送邮件, ...

  6. android 滚动视图(ScrollView)

    为了可以让内嵌布局管理器之中加入多个显示的组件,而且又保证程序不这么冗余,所以可以通过 Activity程序进行控制,向内嵌布局管理器中添加多个组件. ScrollView提供一个显示的容器,可以包含 ...

  7. AJAX的概念介绍

    AJAX学习 1.XMLHttpRequest对象创建 var request= new XMLHttpRequest(); 兼容ie6.ie5 var request; if(windoe.XMLH ...

  8. IOS开发之微博的设计与实现

    // // main.m // Microblog // #import <Foundation/Foundation.h> #import "Person.h" #i ...

  9. virtual-虚方法

    看来本人理论果然不行啊,这个东西折腾死我了.即便是到现在,还是云里雾里.... 个人认为virtual的特点就是可以被override而不是必需的,到目前为止我用它的地方也比较少. public cl ...

  10. C# 无边框窗体移动代码

    C# 无边框窗体移动代码 Point _frmPoint = new Point(); //移动前窗体左上角坐标 Point _mousePoint = new Point(); //按下鼠标时坐标 ...