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. glib源码安装使用方法

    glib库是GTK+和GNOME工程的基础底层核心程序库,是一个综合用途的实用的轻量级的C程序库,它提供C语言的常用的数据结构的定义.相关的处理函数,有趣而实用的宏,可移植的封装和一些运行时机能,如事 ...

  2. 通过一个模拟程序让你明白WCF大致的执行流程

    原文http://www.cnblogs.com/artech/archive/2011/12/07/wcf-how-to-work.html 在<通过一个模拟程序让你明白ASP.NET MVC ...

  3. Android利用Fiddler进行网络数据抓包,手机抓包工具汇总

    Fiddler抓包工具 Fiddler抓包工具很好用的,它可以干嘛用呢,举个简单例子,当你浏览网页时,网页中有段视频非常好,但网站又不提供下载,用迅雷下载你又找不到下载地址,这个时候,Fiddler抓 ...

  4. [置顶] 内存映射失败MapViewOfFile 失败 返回 8

    问题描述1 在使用内存映射方式读写数据时,将文件A的内容拷贝至文件B中,偶尔会出来文件拷贝后的文件,内容为空,或部分为空 问题分析1 怀疑是内存映射方式读写数据的稳定性(可笑的怀疑,内存映射可以Win ...

  5. DEV GridControl 小结(持续添加)

    一.属性: 1.Views OptionsBehavior=>Editable:False  列表不可编辑 OptionsSelection=>EnableAppearanceFocuse ...

  6. JavaSE学习总结第27天_反射 & 设计模式 & JDK5、7、8新特性

      27.01  反射_类的加载概述和加载时机 类的加载:当程序要使用某个类时,如果该类还未被加载到内存中,则系统会通过加载,连接,初始化三步来实现对这个类进行初始化. 加载:就是指将class文件读 ...

  7. Stack(栈)

    Stack(栈)是一种后进先出的数据结构,下面介绍一下栈的具体运用: 一.Stack 中的 empty 函数 stack<int> s( 5 , 10) ; s.empty()  ;   ...

  8. 12-C语言字符串

    目录: 一.字符串 二.字符串输入输出函数 三.指针数组(字符串数组) 回到顶部 一.字符串 1 一组字符数组,以数组的首地址开始,以ASC码的'\0'结束. 2 字符串与普通数组的区别:普通数组没有 ...

  9. ie6与固定定位fixed,+ 条件注释格式注意

    ie6并不支持position:fixed, ie7+都支持fixed定位, ie6固定定位实现方法1: <!DOCTYPE html> <html> <head> ...

  10. 1.Getting Started

    Elasticsearch 是一个高度扩展的开源的全文搜索和分析引擎,它允许你存储,搜索和分析大量的数据和几乎实时. 它通常用于底层的存储.技术,提供应用实现负载的搜索功能和需求. 这里有一些使用的示 ...