gym 100820G Racing Gems(二维LIS,好题)
发布日期:2021-11-12 00:25:48 浏览次数:5 分类:技术文章

本文共 2103 字,大约阅读时间需要 7 分钟。

Racing Gems

You are playing a racing game. Your character starts at the x axis (y = 0) and proceeds up therace track, which has a boundary at the line x = 0 and another at x = w. You may start the raceat any horizontal position you want, as long as it is within the track boundary. The finish line isat y = h, and the game ends when you reach that line. You proceed at a fixed vertical velocity v,but you can control your horizontal velocity to be any value between v/r and v/r, and change itat any time.

There are n gems at specific points on the race track. Your job is to collect as many gems aspossible. How many gems can you collect?

Input

The first line of input contains four space-separated integers n, r, w, and h (1 n 105, 1 r 10,1 w,h 109). Each of the following n lines contains two space-separated integers xi and yi,denoting the coordinate of the ith gem (0 xi w, 0 < yi h). There will be at most one gemper location.

The input does not include a value for v.Output

Print, on a single line, the maximum number of gems that can be collected during the race.

page15image12768

Sample Input

5 1 10 1088

51
46

4779

Sample Output

3

题意:

你在进行一场赛车,初始时你在(x, 0)位置,x属于[0, w]。当到达y=h时,比赛结束。

有n个宝石,第i个宝石的坐标是(xi, yi)。不会有多个宝石在一个位置的情况。

若赛车的y方向的速度为v,那么x方向的速度在[-v/r, v/r]区间,速度可随意调整。

现在不给出v,问最多能够收集到多少宝石。

(1 <= n <= 1e5, 1 <= r <= 10, 1 <= w, h <= 1e9)。

(0 <= xi <= w, 0 <= yi <= h)。

n, r, w, h, xi, yi都为整形变量。

题解:

把题目转换一下就能发现,当赛车在某个位置时,它接下来能拾到的金币的位置是跑道的位置和两条射线夹的面积的相交部分。假如我们让这两条射线分别与赛道两旁的边界相交,那么就能得到两个数字,分别记为a,b

最后我们能发现,本身是一个DAG模型,但是由于都很庞大,但是转换成(a,b) 以后,如果想捡了这个金币后还能捡到下一个金币,那么就要保证下一个金币的A比a大且B比b大,也可以相等。那么这就变成了一个二维无序LIS了,有一种很简单的方法就是,把a从小到大排序,那么之后对b做最长不下降子序列,那么就是答案了。因为此时能保证a绝对不会下降。

#include
#include
#include
#include
#include
#include
#include
using namespace std;#define rep(i,a,n) for (int i=a;i
=a;i--)#define pb push_back#define fi first#define se secondtypedef vector
VI;typedef long long ll;typedef pair
PII;const ll inf=1e18;const ll mod=1000000007;const int maxn=1e5+100;struct node{ ll a,b; bool operator <(const node& s)const{ return a

转载地址:https://blog.csdn.net/fouzhe/article/details/55807180 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:hdu 5845 Best Division(trie+dp,好题)
下一篇:Canada Cup 2016 F. Family Photos(贪心,想法,好题)

发表评论

最新留言

路过按个爪印,很不错,赞一个!
[***.219.124.196]2024年04月25日 11时30分52秒