gym 100820G Racing Gems(二维LIS,好题)
来源:互联网 发布:淘宝摄影单反相机 编辑:程序博客网 时间:2024/06/06 21:40
题目链接
Racing Gems
You are playing a racing game. Your character starts at thex axis (y= 0) and proceeds up therace track, which has a boundary at the linex = 0 and another atx =w. You may start the raceat any horizontal position you want, as long as it is within the track boundary. The finish line isaty =h, and the game ends when you reach that line. You proceed at a fixed vertical velocityv,but you can control your horizontal velocity to be any value between−v/rand v/r, and change itat any time.
There are ngems 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 integersn,r,w, andh (1≤ n≤ 105, 1 ≤ r≤ 10,1≤ w,h≤ 109). Each of the following nlines contains two space-separated integersxiand 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 forv.Output
Print, on a single line, the maximum number of gems that can be collected during the race.
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<iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<vector>#include<queue>#include<stack>using namespace std;#define rep(i,a,n) for (int i=a;i<n;i++)#define per(i,a,n) for (int i=n-1;i>=a;i--)#define pb push_back#define fi first#define se secondtypedef vector<int> VI;typedef long long ll;typedef pair<int,int> 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<s.a; } node(ll x=0,ll y=0):a(x),b(y) {}}a[maxn];ll d[maxn];int main(){ int n,r,w,h; while(~scanf("%d%d%d%d",&n,&r,&w,&h)) { rep(i,1,n+1) { ll x,y; scanf("%lld%lld",&x,&y); a[i].a=1ll*x*r+y; a[i].b=1ll*(w-x)*r+y; } sort(a+1,a+n+1); fill(d,d+n,inf); rep(i,0,n) { *upper_bound(d,d+n,a[i+1].b)=a[i+1].b; } printf("%d\n",lower_bound(d,d+n,inf)-d); } return 0;}
- gym 100820G Racing Gems(二维LIS,好题)
- Gym-100820 Racing Gems(二维LIS)
- GYM 100820 G.Racing Gems(LIS)
- 二维LIS Gym100820G Racing Gems
- Gym100820G/UVALive7374 Racing Gems 二维LIS 思维题
- Racing Gems
- 【2015-2016 ACM-ICPC Pacific Northwest Regional Contest (Div 1)G】【坐标轴变换 LIS】Racing Gems 开车吃宝石,横向速度不能超
- E. LIS of Sequence(好题 LIS )
- UVALive 7374 Racing Gems (最长上升子序列--二分法)
- UVALive 7374 Racing Gems - dp,最长上升子序列
- Tian Ji -- The Horse Racing (好题 逻辑题)
- Gym 100917H Hierarchy 【STL好题】
- 【BZOJ4300】绝世好题【DP】【LIS】
- jdfz-2764 二维LIS
- codeforces gym 100548G
- Gym 100269G-Garage
- CodeForces Gym 100735G
- CodeForces Gym 100735G
- 三维通道下输入和输出一个矩阵
- 常见前端面试题及答案(下)
- ALGO-2 算法训练 最大最小公倍数(贪心算法)
- Java集合框架详解之继承list接口
- 使用Docker构建Gitlab私服
- gym 100820G Racing Gems(二维LIS,好题)
- VBA:Excel使用SQL进行查询
- 别名(Alias)
- 处理机的三级调度
- hibernate自动建表到数据库及spring下自动建表到数据库
- NYOJ2 括号配对问题
- 1046. Shortest Distance
- 巧妙使用WilliamChart绘制出只有两个圆角的柱状图
- Java高并发程序设计笔记(三)之Volatile与Lock