hdu4932(思维题)

用dp暴力枚举,可惜wa 。。

/*
* this code is made by LinMeiChen
* Problem:
* Type of Problem:
* Thinking:
* Feeling:
*/
#include<iostream>
#include<algorithm>
#include<stdlib.h>
#include<string.h>
#include<stdio.h>
#include<math.h>
#include<string>
#include<vector>
#include<queue>
#include<list>
using namespace std; typedef long long lld; typedef unsigned int ud;
#define oo 20000000000.0
double a[55]; double L[105]; int dp[105][55][2]; int main() { int n, m, T;
    scanf("%d", &T); while (T--) {
        scanf("%d", &n); for (int i = 1; i <= n; i++)
            scanf("%lf", &a[i]);
        sort(a + 1, a + 1 + n);
        m = 0; for (int i = 1; i <= n - 1; i++) {
            L[++m] = a[i + 1] - a[i];
            L[++m] = (a[i + 1] - a[i]) / 2; }
        memset(dp, 0, sizeof dp);
        a[n + 1] = oo; for (int i = 1; i <= m; i++) { int len = L[i];
            dp[i][1][1] = 1;
            //dp[i][1][0] = 1;
 for (int j = 2; j <= n; j++) { if (dp[i][j - 1][1] && a[j] - len >= a[j - 1])
                    dp[i][j][1] = 1; else if (dp[i][j - 1][0] && (a[j] - len == a[j - 1] || a[j] - len >= a[j - 1] + len))
                    dp[i][j][1] = 1; else if ((dp[i][j - 1][0] || dp[i][j - 1][1]) && a[j] + len <= a[j + 1])
                    dp[i][j][0] = 1; } } double ans = 0.0; for (int i = 1; i <= m;i++) if (dp[i][n][0] || dp[i][n][1])
            ans = max(ans, L[i]);
        printf("%.3lf\n", ans); } return 0; }
/*
100
3
1 2 3
3
1 2 4
4
1 9 100 10
5
1 3 4 7 8
5
1 3 5 6 7
4
1 2 11 12
5
-7 -3 14 22 31
6
1 0 10 12 18 20
*/

你可能感兴趣的:(HDU)