zoukankan      html  css  js  c++  java
  • codeforces-492B

    B. Vanya and Lanterns
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    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 nl (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.

    Examples
    input
    7 15
    15 5 3 7 9 14 0
    output
    2.5000000000
    input
    2 5
    2 5
    output
    2.0000000000
    Note

    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.

    从这次开始练习用c++做题,A类题会很少做了,这道题的要求是第一行输入路灯数n和路长m,第二行输入路灯所在位置,然后计算路灯照射半径是多少才能覆盖整个路面。

    路灯位置是随机的,需要排序,输出要求精确到小数点后10位,需要用到fixed和setprecision,包含在iomanip文件下。

    #include<iostream>
    #include<iomanip>
    using namespace std;
    
    double MAX(double a, double b, double c)
    {
        if (a >= b && a >= c)
            return a;
        if (b >= c&&b >= a)
            return b;
        if (c >= a&&c >= b)
            return c;
    }
    int main()
    {
        int n, m, a[1005];
        double y=0;
        int i, j, x;
        cin >> n >> m;
    
        for (i = 0;i < n;i++)
            cin>>a[i];
        for(i=0;i<n-1;i++)
            for (j = 0;j < n - i - 1;j++)
            {
                if (a[j] < a[j + 1])
                {
                    x = a[j];
                    a[j] = a[j + 1];
                    a[j + 1] = x;
                }
            }
        for (i = 0;i < n - 1;i++)
        {
            if (a[i] - a[i + 1] > y)
                y = a[i] - a[i + 1];
        }
        y=MAX(y / 2, m - a[0], a[n - 1]);
        cout<<fixed<<setprecision(10)<<y<<endl;
        return 0;
    }
  • 相关阅读:
    常用sql经典语句
    sql创建 自定义函数返回当前日期所在月的第一天最后一天
    洗洗睡了吧啊,何必在意……费口舌不热么
    asp.net Treeview控件
    MSSQL 触发器
    Mssql 通配符
    C#实现所有经典排序算法
    asp.net Treeview
    Asp.net+json 操作类
    Queue 和Stack 的区别
  • 原文地址:https://www.cnblogs.com/chenruijiang/p/7874705.html
Copyright © 2011-2022 走看看