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. python2.7_1.14_编写一个简单的回显客户端/服务器应用

    1.服务端 server.py # -*- coding: utf-8 -*- import socket import argparse host = 'localhost' data_payloa ...

  2. Nancy之实现API

    Nancy之实现API的功能 0x01.前言 现阶段,用来实现API的可能大部分用的是ASP.NET Web API或者是ASP.NET MVC,毕竟是微软官方出产的,用的人也多. 但是呢,Nancy ...

  3. SQL语句的MINUS,INTERSECT和UNION ALL

    SQL语句中的三个关键字:MINUS(减去),INTERSECT(交集)和UNION ALL(并集); 关于集合的概念,中学都应该学过,就不多说了.这三个关键字主要是对数据库的查询结果进行操作,正如其 ...

  4. CDN库地址搜集2

    常用开源库 http://open.bootcss.com/

  5. stl 迭代子的失效

    迭代子是STL中很重要的特性,但是其很脆弱(我个人认为),因为使用它的条件很苛刻,一不小心就失效了.其在两中情况下可能会失效. 1.当容器有插入操作时 在初始化了迭代子后,如果容器有插入操作时,迭代子 ...

  6. Windows Azure 社区新闻综述(#72 版)

    欢迎查看最新版本的每周综述,其中包含有关云计算和 Windows Azure的社区推动新闻.内容和对话. 以下是过去一周基于您的反馈汇集在一起的内容: 文章 ·   在 Windows Azure 移 ...

  7. Android面试题06

    51. 一条最长的短信息约占多少byte? 中文70(包括标点),英文160,160个字节 这个说法不准确, 要跟手机制式运营商等信息有关. 做实验,看源码 ArrayList<String&g ...

  8. HTML5API___manifest

    离线缓存 manifest 在html标签里面增加个属性 mainfest 就可以告诉浏览器缓存文件在哪里. <html manifest='show.manifest' xmlns=" ...

  9. 初步认识ExtJS

    最近因为项目,需要去学习ExtJS的相关内容. 现在对于ExtJS完全是小白一枚. 目前使用的是ExtJS4.2的版本,官网上现在最新版本是6的. 第一个方法:Ext.onReady() Ext.on ...

  10. 我的IOS学习之路(三):手势识别器

    在iOS的学习中,对于手势的处理是极为重要的,如对于图片,我们经常需要进行旋转,缩放以及移动等.这里做一下总结,详见代码. - (void)viewDidLoad { [super viewDidLo ...