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
*/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值