武汉科技大学网络赛1578: LAMP

1578: LAMP

Time Limit: 1 Sec   Memory Limit: 128 MB   64bit IO Format: %lld
Submitted: 12   Accepted: 6
[ Submit][ Status][ Web Board]

Description

Pang Pang is absored in Linux now, he enjoys using LAMP(Linux + Apache + MySQL + php), and runs a great blog on it! One day, the chief of the Pang Pang's hometown found him by his homepage, and send a email to him.

The chief asked him to solve the problem of lamp(not LAMP): The main road of the country has a lot of street lamps, which make the road beautiful at night. But at the same time, the cheif noticed that the light of the lamp overlap at many places, which will cost lots of electricity. However when the chief tried to turn down the lamps, some place were not lit. So he asked Pang to alter the brightness of all the lamps, to make sure that everywhere of the street could be lit up, and minimize the distance of each lamp could light up.

Input

Multiply test cases, terminate with EOF. The descriptions of the test cases follow:

The first line of each test case contains integers N and M (0 < N < 10000 < M < 32768). We assume that the length of the main road is M meters, starts from point 0 and ends at point M. There are N lamps on the road.

The following line contains N integers seperated by single space - the distance between the start point and the i-th street lamp.

Output

For each test case, output one line with a single real number, rounded to two decimal places.

Sample Input 

7 15
14 5 2 7 9 14 1
5 20
1 7 12 18 4

Sample Output

2.50
3.00

//贪心就行,只不过要注意路灯到最左最右边的距离
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
const int maxn = 10005;
using namespace std;

int lamp[maxn];

int main()
{
    int n,m;
    while(scanf("%d %d", &n, &m) != EOF)
    {
        for(int i = 0; i < n; i++)
            scanf("%d",&lamp[i]);
        sort(lamp, lamp+n);
        double ans = (double)max(lamp[0], m - lamp[n-1]);
        for(int i = 1; i < n; i++)
            ans = max(ans, (double)(lamp[i]-lamp[i-1])/2);
        printf("%.2lf\n",ans);
    }
    return 0;
}

你可能感兴趣的:(贪心)