Codeforces  492B   B. Vanya and Lanterns

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

题目:

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

Sample Output

1 2
                

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.

题意:

N盏灯照亮长度为L的街道,使整条街全部被照亮。求灯的最少照亮半径。

分析:

1.将灯的位置排序,先求出相邻两盏灯之间的最大距离,最大距离是每盏灯所照的最大半径的两倍

2.再求第一盏灯到街首的距离和街尾到最后一盏灯的距离

3.比较三个距离的长度,最大值即为所求

代码:

 #include<cstdio>
 #include<iostream>
 #include<algorithm>
 using namespace std;
 ;

 int a[maxn];

 int max(int x,int y)
 {
     return x>y?x:y;
 }

 int main()
 {
     int n,l;
     scanf("%d%d",&n,&l);
     ;i<=n;i++)
     {
         scanf("%d",&a[i]);
     }
     sort(a+,a+n+);   //将灯的位置从小到大排序
     a[]=;  //街首
     a[n+]=l;  //街尾
     ;
     ]-a[],xx=a[n+]-a[n];  //首尾两盏灯到街首和街尾的距离
     ;j<n;j++)   //两盏灯之间的最大距离
     {
         a[j]=a[j+]-a[j];
         if(a[j]>m)
             m=a[j];
     }
     m=max(*b,max(m,*xx));   //求灯照射的最大直径
     double ans=m/2.0;
     printf("%.10lf\n",ans);
     ;
 }

昨天写题目的时候没有写max函数,提交后WA了,所以这次看完题目知道要比较大小,就先写了一个max函数。

Codeforces 492B B. Vanya and Lanterns的更多相关文章

  1. cf492B Vanya and Lanterns

    B. Vanya and Lanterns time limit per test 1 second memory limit per test 256 megabytes input standar ...

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

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

  3. codeforces 677C C. Vanya and Label(组合数学+快速幂)

    题目链接: C. Vanya and Label time limit per test 1 second memory limit per test 256 megabytes input stan ...

  4. CodeForces 492B

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

  5. Vanya and Lanterns

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

  6. 【39.29%】【codeforces 552E】Vanya and Brackets

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  7. 【25.33%】【codeforces 552D】Vanya and Triangles

    time limit per test4 seconds memory limit per test512 megabytes inputstandard input outputstandard o ...

  8. 【30.23%】【codeforces 552C】Vanya and Scales

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  9. 【33.33%】【codeforces 552B】Vanya and Books

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

随机推荐

  1. 几本不错的开源书(to be continued)

    Linux 1.working-on-gnu-linux GNU/Linux 至今已經相當成熟並足以應付日常生活之使用,凍仁也於 2009 年開始使用它來工作至今,將藉由此書 1 來撰寫較有系統的文章 ...

  2. [C++]Infinite House of Pancakes——Google Code Jam 2015 Qualification Round

    Problem It’s opening night at the opera, and your friend is the prima donna (the lead female singer) ...

  3. 依赖注入(DI)和控制反转(IOC)

    依赖注入(DI)和控制反转(IOC) 0X1 什么是依赖注入 依赖注入(Dependency Injection),是这样一个过程:某客户类只依赖于服务类的一个接口,而不依赖于具体服务类,所以客户类只 ...

  4. 10_Segue Example

    10 // // ViewController.swift // Segues Example // // Created by ZC on 16/1/10. // Copyright © 2016年 ...

  5. semver语义化版本号

    semver语义化版本号 语义化版本号各位置的含义 版本号:X.Y.Z X: 代表发生了不兼容的API改变 Y: 代表向后兼容的功能性变化 Z: 代表向后兼容bug fixes 语义化版本号示例 1. ...

  6. STL 全特化/偏特化

    template<class T> class Compare { public: static bool isEqual(const T& lh,const T& rh) ...

  7. poj1363Rails(栈模拟)

    主题链接: id=1363">啊哈哈,点我点我 思路: 这道题就是一道简单的栈模拟. .. .我最開始认为难处理是当出栈后top指针变化了. .当不满足条件时入栈的当前位置怎么办.这时 ...

  8. 扩大或缩小undo表空间

    ***********************************************声明*************************************************** ...

  9. Android studio 开发在真机测试

    真机测试 首先按照这设置android studio:   http://jingyan.baidu.com/article/fea4511a75d627f7ba912540.html 2.打开and ...

  10. jQuery的hover()方法(笔记)

    因为mouseover和mouseout经常一起写,所以出现了hover() hover(function(){},function(){});第一个参数为鼠标移入运行的函数,第二个为鼠标离开运行的函 ...