Gym100820G/UVALive7374 Racing Gems 二维LIS 思维题
2016-08-02 19:59
363 查看
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; }
相关文章推荐
- Codeforces835C-Star sky(二维前缀和+思维)
- HDU - 5773 The All-purpose Zero(思维+LIS)
- SGU 521 North-East ( 二维LIS 线段树优化 )
- CodeForces 798D Mike and distribution(二维贪心 + 思维)
- BZOJ2241:打地鼠(二维前缀和 & 思维)
- Atcoder 500 Checker 思维+二维前缀和
- HDU:5256 序列变换(LIS-n*logn解法+思维+技巧)
- UVA10285 二维 LIS
- 【HDU】-5773-The All-purpose Zero(LIS变形,思维)
- HDU 5925 Coconuts [二维离散化]【杂类+思维】
- CCCC-GPLT L2-014. 列车调度 思维/LIS
- Codeforces 835C Star sky【思维+暴力预处理二维前缀和】
- HDU-1051 Wooden Sticks 【二维LIS(STL应用)+排序】
- HDU:1025 Constructing Roads In JGShining's Kingdom(LIS-n*logn解法+思维)
- 20161026的考试】KMP,二维LIS,DAG删一个点求最长路径最小值(BZOJ 3832)
- 798D的二维贪心与C的思维
- BNU 49048 神奇的身高【思维+LIS】
- AGC 015C Nuske vs Phantom Thnook 思维+二维前缀和
- hdu 5256 序列变换 LIS 变型 思维转化
- gym 100820G Racing Gems(二维LIS,好题)