Codeforces 492B B. Vanya and *s

时间:2022-08-28 12:36:59

Codeforces  492B   B. Vanya and *s

题目链接: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 *s. 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 * is at the point ai. The * 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 *s.

Vanya wonders: what is the minimum light radius d should the *s have to light the whole street?

Input

The first line contains two integers n, l (1 ≤ n ≤ 1000, 1 ≤ l ≤ 109) — the number of *s and the length of the street respectively.

The next line contains n integers ai (0 ≤ ai ≤ l). Multiple *s can be located at the same point. The *s 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 * will light the segment [0, 4] of the street, and the second * 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 *s的更多相关文章

  1. cf492B Vanya and *s

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

  2. codeforces 492B&period; Vanya and *s 解题报告

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

  3. codeforces 677C C&period; Vanya and Label&lpar;组合数学&plus;快速幂&rpar;

    题目链接: 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 *s. Consid ...

  5. Vanya and *s

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

  6. 【39&period;29&percnt;】【codeforces 552E】Vanya and Brackets

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

  7. 【25&period;33&percnt;】【codeforces 552D】Vanya and Triangles

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

  8. 【30&period;23&percnt;】【codeforces 552C】Vanya and Scales

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

  9. 【33&period;33&percnt;】【codeforces 552B】Vanya and Books

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

随机推荐

  1. AJAX回调函数,返回JSON格式,应该返回自定义状态STATUS,但是却返回200

    返回200应该是方法已经执行通的意思,但是没返回自定义的status,仔细一看json格式拼错了...

  2. SQL Server中字符串转化为GUID的标量函数实现

        还是工作中遇到的需求,有时候和外部的系统对接,进行数据的核对功能,外部的系统有时候主键字段列数据类是UNIQUEIDENTIFER(GUID)类型的字符串格式,去除了GUID格式中的分隔符“- ...

  3. JSP显示不完全问题

    这个问题出现之后其实有点让我手足无措,因为根本不知道原因出在哪儿. 因为出现这个问题之后修改过一次代码,所以我以为是因为这次修改出现的问题. 但细想之下,这次的修改根本没有涉及到任何有关这方面的东西. ...

  4. Gridview AutoGenerateColumns属性

    第一篇随笔,以后会陆续的把刚开始工作时的知识点都记录下来,毕竟现在用WebForm的不多了~ AutoGenerateColumns MSDN 说明 : 获取或设置一个值,该值指示是否为数据源中的每个 ...

  5. R︱Rstudio 1&period;0版本尝鲜(R notebook、下载链接、sparkR、代码时间测试profile)

    每每以为攀得众山小,可.每每又切实来到起点,大牛们,缓缓脚步来俺笔记葩分享一下吧,please~ --------------------------- 2016年11月1日,RStudio 1.0版 ...

  6. &lbrack;面试&rsqb;StringBuilder StringBuffer源码粘贴&lpar;并非源码分析&comma; 请绕道&rpar;

    StringBuilder StringBuffer 源码 这里只是我个人笔记, 并没有在这篇文章里做任何技术分享, 请同学们绕道- -.如果需要我会后期补上的..... 本来是想分析源码来着, 但是 ...

  7. PHP自动加载&lpar;&lowbar;&lowbar;autoload和spl&lowbar;autoload&lowbar;register&rpar;

    一:什么是自动加载 我们在new出一个class的时候,不需要手动去require或include来导入这个class文件,而是程序自动帮你导入这个文件不需要手动的require那么多class文件了 ...

  8. iptables日志与limit参数

    在处理工作问题的时候需要查看防火墙的日志,由于默认日志都是在系统日志里/var/log/messages里面.需要对rsyslog做设置. 首先编辑配置文件/etc/rsyslog.conf如下: # ...

  9. css 权威指南笔记

    部分属性选择: 选择class 属性中包含warning的元素 [class~="warning"]{font-weight:bold} 子串匹配属性选择器: 在现代浏览器中得到支 ...

  10. PokeCats开发者日志(七)

      现在是PokeCats游戏开发的第十二天的晚上,很不幸提交到的三个平台(360开放平台,腾讯开放平台,华为应用市场)都没通过,著作权申请也被打回来了.   心中一万只*在奔腾.   得了,看来 ...