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

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

Hint

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.

题意:一条街,起点0,长度L。在街上有多盏灯,每盏灯的照亮半径一样,求最小半径使得整个街道都是亮的...(可以一个位子放多盏灯,0和L点都可以放灯)

解题思路:    第一种情况,0和L都有放灯,那么答案就是求相邻两盏灯之间的最大距离的一半,因为只有这样才可能照亮整个街道。就可木桶原理差                                不多。

      第二种情况,首尾有可能没有放,或者只放了一个,就和案例2一样(位置0到第一个灯的距离为2大于用情况一求的0.5,所以答案就是                               2)

      这样的话 就可以总结下,只要求出相邻最大的距离的一半,然后和位置0到第一个灯的距离c1,以及最后一个灯到L的距离c2。他们进行                                    比较 ,最后输出他们三个中最大值就好了 

代码如下:(额 忘记说了 ,还要排个序.....)

  1. #include <stdio.h>
  2. #include <algorithm>
  3. using namespace std;
  4. int a[];
  5. int main()
  6. {
  7. int n,l,q,c1,c2;
  8. while(scanf("%d%d",&n,&l)!=EOF)
  9. {
  10. double r=,ans=;
  11. for(int i=; i<n; i++)
  12. scanf("%d",&a[i]);
  13. sort(a,a+n);
  14. for(int i=; i<n; i++)
  15. {
  16. q=a[i]-a[i-];
  17. if(q>r) r=q;
  18. }
  19. c1=a[];
  20. c2=l-a[n-];
  21. ans=max(c1,c2);
  22. ans=max(r/,ans);
  23. printf("%.10lf\n",ans);
  24. }
  25. return ;
  26. }

  

      

      

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 Name That Tune ( 期望DP )

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

  4. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  5. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  6. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  7. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  8. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  9. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

随机推荐

  1. Android(java)学习笔记72:线程的状态转换图以及常见执行情况

    1. 线程的状态转换图以及常见执行情况: 2. 线程状态类型: (1)新建状态(New):新创建了一个线程对象.(2)就绪状态(Runnable):线程对象创建后,其他线程调用了该对象的start() ...

  2. Java 8: Lambdas和新的集合Stream API

    Lambda是Java8的主要特色,Java 8: Lambdas & Java Collections | zeroturnaround.com一文介绍了使用Lambda集合处理大量数据的方 ...

  3. C#中,为什么结构体也可以设置构造函数?

    结构体派生自ValueType,ValueType派生自Object,可访问Object的方法.结构体是一种缩小版的类.结构体不能继承.结构体总是有一个无参数的默认构造函数,不允许替换.结构体可指定字 ...

  4. KindEditor图片上传到七牛云

    自己做了一个网站,编辑器用的是KindEditor,平时会涉及到KindEditor自带的图片上传,但是服务器用的是虚拟主机,没多少空间,就一直想着把图片放在免费的云存储空间,之前看KindEdito ...

  5. Linux下安装配置Node及memcached

    这篇主要是记录Linux下安装Node及memcached遇到的问题及安装配置过程,方便日后查阅 Node安装及配置 [root@hostname ~]tar zxvf node-v0.12.4.ta ...

  6. VB.net 字符串 分割 及 重新倒序组装

    ''' <summary> ''' split with ">>>>" , and inverted order ''' </summar ...

  7. Bootstrap简单Demo(2015年05月-18日)

    Bootstrap的简单使用 1.Bootstrap是什么? 这是Bootstrap官网上对它的描述:Bootstrap是最受欢迎的HTML.CSS和JS框架,用于开发响应式布局.移动设备优先的WEB ...

  8. Spring与Hibernate整合之通用Dao的实现

    在上一篇文章中写了如何直接利用HibernateTemplate进行数据库操作,但在一般的项目中很少直接得到HibernateTemplate的Bean对象从而操作数据库的,下面就简要介绍一下实现通用 ...

  9. 一个js排序

     ]                           d = d[a];          e = e[a];                                d =         ...

  10. bootstrap学习起步篇:初识bootstrap之html5语法构建hello篇(一)

    目前选择使用bootstrap作为前端页面模板,是件很省心的事情.官网上给出的实例和教程也很多.在实际使用过程中,我们也许还要借助文档去了解它的元素和样式.但也不能减少我们使用他的兴趣. 我准备将其整 ...