题目描述

You  are  playing  a  racing  game.  Your  character  starts  at  the  X-axis  line  (y=0)  and proceeds up the racetrack, which has a boundary at the line x=0 and x=w.  The finish is at  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,  where  r  is  a  fixed  ratio.  You  may  change  your  horizontal velocity at any time, but your vertical velocity must remain fixed. 
There are gems at specific points on the race track. Your job is to collect as many gems as possible (they all have the same value). 
How many gems can you collect? You may start at any horizontal position you want (but your vertical position must be 0 at the start).

输入

Each input will consist of a single test case. Note that your program may be run multiple times  on  different  inputs.  The  first  line  will  contain  four  integers:  n  (1≤n≤105 )  is  the number  of  gems,  r  (1≤r≤10)  is  the  ratio  of  vertical  velocity  to  maximum  horizontal speed, w (1≤w≤109 ) is the width of the track, and h (1≤h≤109 ) is the height of the finish line.    Following  this  will  be  n  lines,  each  containing  an  integer  x  and  y  coordinate 
(0≤x≤w,1≤y≤h), containing the coordinate of a gem.  All gems will lie on the race track.  None will be on the start line.

输出

Output  a  single  integer  on  a  line  by  itself  representing the maximum number of gems that you can collect.

样例输入

5 1 10 10
8 8
5 1
4 6
4 7
7 9

样例输出

3

题目链接:点击查看


题目大意:一个在二维坐标平面开展的跑车游戏,首先规定赛道边界:左右边界分别为x=0和x=w,上下边界分别为y=0和y=h,现在要求从y=0跑到y=h,现在规定一个速度比率,也就是,在路上有许多宝石,我们需要尽可能多的去吃到宝石,问我们最后到达终点的时候,吃到宝石数的最大值是多少?

题目分析:这个题目我们算是分析了好久好久吧,先从网上拿来一张图,更好理解一下这个题目:

一开始我们大概就分析到了这个地方,先给宝石对于纵坐标排序,然后可以设一个dp[i]代表在吃到宝石i的情况下获得的最大值,那么我们很轻松就能看出来,dp[i]=max(dp[i],dp[j]+1)(1<=j<i) ,也就是我们需要在前i-1个宝石中寻找满足斜率条件的最大值,但这样一来时间复杂度就变为了n*n,对于这个题目而言不可行,后来我们讨论了半天,最后终于得出了结论(%yh学长),就是将rate当一个斜率来看待,有了每一个点和斜率了,就可以求出直线方程,然后求出对于x=0和x=w的交点纵坐标,就像上图一样,因为每个宝石所构成的一个带角度的范围内的其余宝石,才能接受当前宝石的状态转移,这个应该不难想到,随后我们对于任意一边的坐标升序排序,然后对于另一边的坐标找一下最长不下降子序列即可

代码:

#include<iostream>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cctype>
#include<stack>
#include<queue>
#include<list>
#include<vector>
#include<set>
#include<map>
#include<sstream>
#include<unordered_map>
using namespace std;typedef long long LL;const int inf=0x3f3f3f3f;const int N=1e5+100;struct Node
{LL x,y;bool operator<(const Node& a)const{return x<a.x;}
}a[N];LL d[N];int main()
{
//  freopen("input.txt","r",stdin);LL n,rate,w,h;scanf("%lld%lld%lld%lld",&n,&rate,&w,&h);for(int i=1;i<=n;i++){LL x,y;scanf("%lld%lld",&x,&y);a[i].x=rate*x+y;a[i].y=rate*(w-x)+y;}sort(a+1,a+1+n);int len=1;memset(d,0,sizeof(d));d[1]=a[1].y;for(int i=2;i<=n;i++){if(a[i].y>=d[len]){d[++len]=a[i].y;}else{int j=upper_bound(d+1,d+1+len,a[i].y)-d;d[j]=a[i].y;}}cout<<len<<endl;return 0;
}

中石油训练赛 - Racing Gems(最长不下降子序列)相关推荐

  1. 中石油训练赛 - Trading Cards(最大权闭合子图)

    题目大意:给出 n 个卡片,可以自由买卖,且价格都是相同的,再给出 m 个集合,如果已经得到了其中一个集合中的卡片,那么可以获得该集合的收益,问如何操作可以使得收益最大化 题目分析:最大权闭合子图的模 ...

  2. 中石油训练赛 - Watch Later(状压dp)

    题目链接:点击查看 题目大意: 给出一个长度为 n 的字符串,字符串中共有 k 种不同的字符,现在问删除掉所有字符的最小操作数,对于每种字符需要确定一个先后顺序,每次需要删除掉当前所有的这种字符才能去 ...

  3. 中石油训练赛 - Swapity Swap(矩阵快速幂)

    题目描述 Farmer John's N cows (1≤N≤100) are standing in a line. The ith cow from the left has label i, f ...

  4. 中石油训练赛 - Switches(高斯消元求逆矩阵+逆矩阵求线性方程组)

    题目大意:给出一个 n * n 的布尔矩阵表示开关与灯的关系,现在每个灯来说,是否存在一种开关的集合,使得恰好使得只有当前灯是打开状态,其余灯都是熄灭状态,分别输出方案 题目分析:将开关视为变元,将灯 ...

  5. 中石油训练赛 - Swapping Places(字典序最小的拓扑排序)

    题目链接:点击查看 题目大意:给出 s 个字符串表示种类,再给出 m 个朋友关系,表示两个种类的动物是朋友,现在给出一个长度为 n 的种类排列,规定相邻两个是朋友的种类的动物可以交换位置,问如何操作, ...

  6. 中石油训练赛 - Gone Fishing(固定大小的圆可以覆盖最多的点)

    题目大意:在二维平面中给出 n 个点,再给出一个固定大小的圆,问如何放置这个圆可以使其覆盖最多的点 题目分析:首先不难想到一种 n^3 的做法,就是两层循环去枚举两个点,因为两个不同的点就可以确定下来 ...

  7. 中石油训练赛 - Russian Dolls on the Christmas Tree(树上启发式合并/主席树)

    题目链接:点击查看 题目大意:给出一棵 n 个节点的树,以点 1 为根,现在对于每个节点作为根的子树求解:子树中有多少个编号不相交的连续子段,如:1 2 4 5 7,共有三个连续的段,分别为 [ 1 ...

  8. 中石油训练赛 - Check List(线段树维护偏序问题)

    题目大意:给出 n 个点,需要计算出满足下列条件的三元对 ( i , j , k ) 的数量: x[ i ] < x[ j ] < x[ k ] y[ k ] > y[ i ] &g ...

  9. 中石油训练赛 - Bad Treap(数学)

    题目链接:点击查看 题目大意:给出笛卡尔树的定义,现在要求给出 n 个点对 ( x , sin( x ) ),使得笛卡尔树的高度尽可能大 题目分析:如果想让笛卡尔树的高度尽可能大,令其退化为一条链即可 ...

最新文章

  1. BZOJ 3289 Mato的文件管理 | 莫队 树状数组
  2. PHP优于Node.js的五大理由
  3. ASP.Net请求处理机制初步探索之旅 - Part 1 前奏
  4. 如何优雅的追到女神夕小瑶
  5. 根据经纬度求最近点的三种解法java实现
  6. vue 组件根元素显示优化
  7. python写一个类600行代码_带你领略算法的魅力,一个600行代码的分词功能实现(一)...
  8. Linux qt5无法输入中文的解决办法
  9. 2021信创产业分类排行
  10. 【微信技术-微信小程序】------ 使用ColorUI组件简单入门
  11. 计算机二级vb考试教材,2020年9月全国计算机二级易考套餐:二级VB考试题库+教材...
  12. 正运动技术 运动控制卡应用开发教程之C#
  13. css手册.chm + W3CSchool.chm下载
  14. SAP_ABAP 采购价格条件报表(改进版1)
  15. UVA11991 Easy Problem from Rujia Liu?(第K个V的位置)
  16. 什么是 java 序列化?什么情况下需要序列化?
  17. 专利法上的抽象思想与具体技术 ——计算机程序算法的客体属性分析
  18. Design pattern : Singleton
  19. 高维数组matlab,MATLAB 高维数组
  20. 解决问题备忘:Http头Authorization值格式错误,请参考《微信支付商户REST API签名规则》

热门文章

  1. MySQL语法规范介绍
  2. MySQL高级 - 常用工具 - mysqlbinlog与mysqldump
  3. MySQL高级 - SQL优化 - 子查询优化
  4. MyBatis 架构分层与模块划分-核心处理层
  5. Nacos安装和服务注册
  6. 基于JWT的API权限校验:需求分析
  7. 类属性-类属性的定义及使用
  8. SpringBoot高级消息-RabbitMQ运行机制
  9. php5.6.16,OSX 10.11 中重新编译PHP5.6.16问题
  10. Spring Boot配置文件有提示