Program B--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 1515 5 3 7 9 14 0

Output

2.5000000000

Input

2 52 5

Output

2.0000000000

题目大意:Vanya走在一条长为l的街上,这条街上有n盏灯,这n盏可以在l上的随意位置,所以灯照射的半径都相同,求灯的最小半径使得整条街都有光照。

注意:任意两盏灯必须要相邻才行。

分析:这题可以直接用暴力求解,不过要注意两点。首先n盏灯中包括左右两个端点,则只要知道其中两盏灯距离最大(用sum表示)就可以了,

它的一半就是要求的最小半径;

如果只包括其中一个端点或两个端点都不包括,先将左端点到第一盏的灯距离(用c表示)与最后一盏灯到右端点的距离(用d表示)进行比较,

取较大的值赋给c,由于c本身就是半径,所以如果c的2倍大于或等于距离最大的两盏灯,输出c,否则输出sum的一半。

代码如下:
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int main()
{
    int n,l,a[1005],c,p,q,flag,i,d;
    double sum;
    while(scanf("%d%d",&n,&l)==2)
    {
        c=0,d=0,p=0,q=0,sum=0.0,flag=0;
        for(i=0;i<n;i++)
            scanf("%d",&a[i]);
        sort(a,a+n);
        for(i=0;i<n&&a[i]<=l;i++)
        {
            if(a[0]==0&&a[n-1]==l)
                flag=1;
            q=a[i]-p;
            p=a[i];
            if(q>=sum)
                sum=q;
        }
        if(!flag)
        {
            if(a[0]!=0)
                c=a[0];
            if(a[n-1]!=l)
                d=l-a[n-1];
            c=max(c,d);
            if(2*c>=sum)
                printf("%.10lf\n",(double)c);
            else
                printf("%.10lf\n",sum/2);

        }
        else
            printf("%.10lf\n",sum/2);

    }
    return 0;
}
 



				
时间: 2024-10-07 11:51:07

Program B--CodeForces 492B的相关文章

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 lanter

Codeforces Round #174 (Div. 2)---D. Cow Program(dp, 记忆化搜索)

Farmer John has just given the cows a program to play with! The program contains two integer variables, x and y, and performs the following operations on a sequence a1,?a2,?-,?an of positive integers: Initially, x?=?1 and y?=?0. If, after any step, x

CodeForces 468A Program F

Description Little X used to play a card game called "24 Game", but recently he has found it too easy. So he invented a new game. Initially you have a sequence of n integers: 1, 2, ..., n. In a single step, you can pick two of them, let's denote

Codeforces 283B Cow Program

题意:给你a[2] - a[n], 一个初始x = 1,初始y = 0  ,执行下面步骤 1) x +=a[x] ,y += a[x] 2) x -= a[x] ,y += a[x] 3)重复1-2步骤.只要中间x <=0 || x > n  就跳出.输出y的值 问你a[1] 从 [1,n-1]分别的值为多少. 解题思路:dfs 求 dp[i][0/1]  求以加法进入 i 和以减法进入 i 能得到的值. 解题代码: 1 // File Name: 283b.cpp 2 // Author:

CodeForces 540C Program D

Description You play a computer game. Your character stands on some level of a multilevel ice cave. In order to move on forward, you need to descend one level lower and the only way to do this is to fall through the ice. The level of the cave where y

CodeForces 534D Program B

Description On February, 30th n students came in the Center for Training Olympiad Programmers (CTOP) of the Berland State University. They came one by one, one after another. Each of them went in, and before sitting down at his desk, greeted with tho

Codeforces 772A Voltage Keepsake - 二分答案

You have n devices that you want to use simultaneously. The i-th device uses ai units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·ai units of power. The i-th device currently has bi units of power store

Codeforces Round #339 (Div. 2) B. Gena&#39;s Code

B. Gena's Code It's the year 4527 and the tanks game that we all know and love still exists. There also exists Great Gena's code, written in 2016. The problem this code solves is: given the number of tanks that go into the battle from each country, f

CodeForces 1B. Spreadsheets(模拟)

题目链接:http://codeforces.com/problemset/problem/1/B B. Spreadsheets time limit per test 10 seconds memory limit per test 64 megabytes input standard input output standard output In the popular spreadsheets systems (for example, in Excel) the following