Gym100820G/UVALive7374 Racing Gems 二维LIS 思维题

探讨赛车在限定区域内捡取金币的问题,利用二维LIS算法求解赛车能获取的最大金币数量。通过数学建模将问题转化为计算二维LIS,提供了一种高效的解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Gym100820G/UVALive7374  Racing Gems 二维LIS 思维题

题目链接 Vjudge
题意:赛车在宽为W,高度为H的跑道上捡金币。假设赛车垂直速度为V0,水平速度为V1,有 -V0/R<= V1 <= V0/R。现在给定W,H,R和N个金币的坐标,求小车从y=0的任意横坐标出发,到达y=H时,所能获得的最多金币数。
这就是今年的校赛的母题啊!
牢骚:神奇的思维。前几天做过了一个二维LIS,今天做这个题目依旧还是没有与二维的LIS联系起来。唉!
分析:分析(x0, y0)这个位置上的金币。 假如赛车到了这个位置,那么接下来可达的范围就如下图所示了。 每个点都与x=0,与x=W 分别有一个交点, 从图中可以发现, 从一个点(X0,Y0)可以到达另外一个点(X1, Y1)当且仅当 RX0+Y0<=RX1+Y1 并且 R(W-X0)+Y0 <= R(W-X1)+Y1。 对于每个点(xi,yi),令a=R*xi + yi, b = R*(W-xi)+yi。 只需要计算(a, b) 二维的LIS就可以的。求二维的LIS步骤: 先对其中一维进行排序,然后对另一维求最长不降子序列。

#include <cmath>
#include <queue>
#include <vector>
#include <cstdio>
#include <string>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
using namespace std;

using namespace std;

#define FIN             freopen("input.txt","r",stdin)
#define FOUT            freopen("output.txt","w",stdout)
#define fst             first
#define snd             second
typedef __int64         LL;
typedef pair<int, int>  PII;
typedef pair<LL, LL>    PLL;
const int MAXN = 1e5 + 5;

int N, R, W, H;
PLL F[MAXN];
LL I[MAXN];
int LIS() {
    int len = 0;
    I[len ++] = F[0].snd;
    for (int i = 1; i < N; i++) {
        if (F[i].snd >= I[len - 1]) I[len ++] = F[i].snd;
        else {
            int pos = upper_bound (I, I + len, F[i].snd) - I;
            I[pos] = F[i].snd;
        }
    }
    return len;
}

int main() {
#ifndef ONLINE_JUDGE
    FIN;
#endif // ONLINE_JUDGE
    while (~scanf ("%d %d %d %d", &N, &R, &W, &H) ) {
        int x, y;
        for (int i = 0; i < N; i++) {
            scanf ("%d %d", &x, &y);
            F[i].fst = (LL) R * x + y;
            F[i].snd = (LL) R * (W - x) + y;
        }
        sort (F, F + N);
        int len = LIS();
        printf ("%d\n", len);
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值