zoukankan      html  css  js  c++  java
  • CodeForces 492B

    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

    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[1050];
     5 int main()
     6 {
     7     int n,l,q,c1,c2;
     8     while(scanf("%d%d",&n,&l)!=EOF)
     9     {
    10         double r=0,ans=0;
    11         for(int i=0; i<n; i++)
    12             scanf("%d",&a[i]);
    13         sort(a,a+n);
    14         for(int i=1; i<n; i++)
    15         {
    16             q=a[i]-a[i-1];
    17             if(q>r) r=q;
    18         }
    19         c1=a[0];
    20         c2=l-a[n-1];
    21         ans=max(c1,c2);
    22         ans=max(r/2,ans);
    23         printf("%.10lf
    ",ans);
    24     }
    25     return 0;
    26 }

      

           

          

  • 相关阅读:
    [BZOJ1584][Usaco2009 Mar]Cleaning Up 打扫卫生
    CSS浮动
    Django by example -----1总结
    C#函数重载
    linux目录的特点
    Linux调优
    linux
    对齐方式
    19-10-25-G-悲伤
    19-10-24-H
  • 原文地址:https://www.cnblogs.com/huangguodong/p/4716076.html
Copyright © 2011-2022 走看看