Description

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 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.

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 Input

Input
7 15
15 5 3 7 9 14 0
Output
2.5000000000
Input
2 5
2 5
Output
2.0000000000

题目大意:Vanya走在一条长为l的街上,这条街上有n盏灯,这n盏可以在l上的随意位置,所以灯照射的半径都相同,求灯的最小半径使得整条街都有光照。

注意:任意两盏灯必须要相邻才行。

分析:这题可以直接用暴力求解,不过要注意两点。首先n盏灯中包括左右两个端点,则只要知道其中两盏灯距离最大(用sum表示)就可以了,

它的一半就是要求的最小半径;

如果只包括其中一个端点或两个端点都不包括,先将左端点到第一盏的灯距离(用c表示)与最后一盏灯到右端点的距离(用d表示)进行比较,

取较大的值赋给c,由于c本身就是半径,所以如果c的2倍大于或等于距离最大的两盏灯,输出c,否则输出sum的一半。

代码如下:
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int main()
{
int n,l,a[1005],c,p,q,flag,i,d;
double sum;
while(scanf("%d%d",&n,&l)==2)
{
c=0,d=0,p=0,q=0,sum=0.0,flag=0;
for(i=0;i<n;i++)
scanf("%d",&a[i]);
sort(a,a+n);
for(i=0;i<n&&a[i]<=l;i++)
{
if(a[0]==0&&a[n-1]==l)
flag=1;
q=a[i]-p;
p=a[i];
if(q>=sum)
sum=q;
}
if(!flag)
{
if(a[0]!=0)
c=a[0];
if(a[n-1]!=l)
d=l-a[n-1];
c=max(c,d);
if(2*c>=sum)
printf("%.10lf\n",(double)c);
else
printf("%.10lf\n",sum/2); }
else
printf("%.10lf\n",sum/2); }
return 0;
}
 




Program B--CodeForces 492B的更多相关文章

  1. Codeforces 492B B. Vanya and Lanterns

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

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

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

  3. CodeForces 492B

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

  4. Codeforces 492B Name That Tune ( 期望DP )

    B. Name That Tune time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  5. [Benchmark] Codeflaws: A Programming Competition Benchmark for Evaluating Automated Program Repair Tools

    Basic Information Publication: ICSE'17 Authors: Shin Hwei Tan, Jooyong Yi, Yulis, Sergey Mechtaev, A ...

  6. Codeforces Round #443 (Div. 1) A. Short Program

    A. Short Program link http://codeforces.com/contest/878/problem/A describe Petya learned a new progr ...

  7. Codeforces Round #879 (Div. 2) C. Short Program

    题目链接:http://codeforces.com/contest/879/problem/C C. Short Program time limit per test2 seconds memor ...

  8. Codeforces Round #174 (Div. 1) B. Cow Program(dp + 记忆化)

    题目链接:http://codeforces.com/contest/283/problem/B 思路: dp[now][flag]表示现在在位置now,flag表示是接下来要做的步骤,然后根据题意记 ...

  9. Codeforces Round #443 (Div. 2) C. Short Program

    C. Short Program time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  10. Codeforces 879C/878A - Short Program

    传送门:http://codeforces.com/contest/879/problem/C 本题是一个位运算问题——位运算的等价变换. 假设位运算符“&”“|”“^”是左结合的,且优先级相 ...

随机推荐

  1. 关于时区的时间的详解,比如UTC\GMT等

    UTC 和 GMT 及 北京时间的关系 UTC和GMT,这两者几乎是同一概念.它们都是指的格林尼治标准时间,只不过UTC的称呼更为正式一点.两者的区别在于前者是一个天文 上的概念,而 后者是基于一个原 ...

  2. python操作mongodb之八地理索引空间数据

    from pymongo import MongoClient, GEO2D #使用geo_example库 db = MongoClient('192.168.30.252',27017).geo_ ...

  3. jquery 学习

    地址:http://www.w3school.com.cn/jquery/jquery_dom_add.asp

  4. 【转】 C++ map的基本操作和使用

    1.map简介 map是一类关联式容器.它的特点是增加和删除节点对迭代器的影响很小,除了那个操作节点,对其他的节点都没有什么影响.对于迭代器来说,可以修改实值,而不能修改key. 2.map的功能 自 ...

  5. JavaScript 3D图表

    在说3D图表以前,首先要明确两个概念,一个是数据的维度,一个是呈现数据载体的维度.对于数据的维度,一维的数据呈现,但是呈现的载体是二维的平面图,比如饼图: 已经能够很清晰地观察到数据的分布情况.数据如 ...

  6. Feistel密码结构

    分组密码:是一种加解密方案,将输入的明文分组当作一个整体出来,输出一个等长的密文分组. 典型的分组大小为64位和128位.密钥长度一般为128位.迭代轮数典型值为16轮. Feistel 密码结构是用 ...

  7. python中cPickle的用法

    import cPickle as p f = file('data.txt' , 'w') data = (1 , 'A' , "hello") p.dump(data , f) ...

  8. Andriod使用webview控件往APP里内嵌网页

    转自博文:http://www.cnblogs.com/JuneZhang/p/4148542.html 1.布局文件片段:res-layout <WebView android:id=&quo ...

  9. BZOJ1718 [Usaco2006 Jan] Redundant Paths 分离的路径

    给你一个无向图,问至少加几条边可以使整个图变成一个双联通分量 简单图论练习= = 先缩点,ans = (度数为1的点的个数) / 2 这不是很好想的么QAQ 然后注意位运算的优先级啊魂淡!!!你个sb ...

  10. div在固定高的文字垂直居中

    <div style='display:table; height:100px;'> <div style='display:table-cell; vertical-align:  ...