HDU 2155 小黑的镇魂曲

题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=2155

思路:大神地址:http://www.aiuxian.com/article/p-1671720.html

代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <cstring>
#include <climits>
#include <cmath>
#include <cctype>
const double inf = 2100000;
typedef long long LL;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
using namespace std;
double dp[1010][2];
struct node
{
    double left;
    double right;
    double height;
} a[1010];
bool cmp(node x,node y)
{
    if(x.height != y.height)
        return x.height > y.height;
    else
        return x.left < y.left;
}
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n;
        double x,y,max1,m;
        scanf("%d%lf%lf%lf%lf",&n,&x,&y,&max1,&m);
        a[0].left = a[0].right = x;
        a[0].height = y;
        for(int i=1; i<=n; i++)
            scanf("%lf%lf%lf",&a[i].left,&a[i].right,&a[i].height);
        sort(a+1,a+n+1,cmp);
        a[n+1].left = 0;
        a[n+1].right = 1000;
        a[n+1].height = 0;
        for(int i=1; i<=n+1; i++)
            dp[i][0] = dp[i][1] = inf;
        dp[0][0] = 0;
        dp[0][1] = 0;
        for(int i=1; i<=n+1; i++)
        {
            for(int j=0; j<i; j++)
            {
                if(a[i].height - a[j].height > max1) break;
                if(a[j].left >= a[i].left && a[j].left <= a[i].right)
                {
                    if(i == n+1)
                    {
                        dp[i][0] = min(dp[i][0],dp[j][0] + a[j].height);
                        //printf("%lf\n",dp[i][0]);
                        dp[i][1] = min(dp[i][1],dp[j][1] + a[j].height);
                        //printf("%lf\n",dp[i][1]);
                    }
                    else
                    {
                        dp[i][0] = min(dp[i][0],dp[j][0] + a[j].left - a[i].left + a[j].height - a[i].height);
                        dp[i][1] = min(dp[i][1],dp[j][0] + a[i].right - a[j].left + a[j].height - a[i].height);
                    }
                }
            }
            for(int j=0; j<i; j++)
            {
                if(a[i].height - a[j].height > max1) break;
                if(a[i].right >= a[j].left && a[i].right <= a[j].right)
                {
                    if(i == n+1)
                    {
                        dp[i][0] = min(dp[i][0],dp[j][0] + a[j].height);
                        //printf("%lf\n",dp[i][0]);
                        dp[i][1] = min(dp[i][1],dp[j][1] + a[j].height);
                        //printf("%lf\n",dp[i][1]);
                    }
                    else
                    {
                        dp[i][0] = min(dp[i][0],dp[j][1] + a[j].right - a[i].left + a[j].height - a[i].height);
                        dp[i][1] = min(dp[i][1],dp[j][1] + a[i].right - a[j].right + a[j].height - a[i].height);
                    }
                }
            }
            //printf("%d %lf %lf\n",i,dp[i][0],dp[i][1]);
        }
        if(dp[n+1][0] <= m || dp[n+1][1] <= m)
            printf("NO\n");
        else
            printf("YES\n");
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值