ACM: Racing Gems - 最长递增序列
Racing Gems

You are playing a racing game. Your character starts at the x axis (y = 0) and proceeds up the race track, which has a boundary at the line x = 0 and another at x = w. You may start the race at any horizontal position you want, as long as it is within the track boundary. The finish line 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, and change it at any time.
There are n gems at specific points on the race track. Your job is to collect as many gems as possible. 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 gem per 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.
|
Sample Input |
Sample Output 3 |
|
5 1 10 10 |
|
|
8 8 |
|
|
5 1 |
|
|
4 6 |
|
|
4 7 |
|
|
7 9 |
|
Sample Input |
Sample Output 3 |
|
5 1 100 100 |
|
|
27 75 |
|
|
79 77 |
|
|
40 93 |
|
|
62 41 |
|
|
52 45 |
|
Sample Input |
Sample Output 4 |
|
10 3 30 30 |
|
|
14 9 |
|
|
2 20 |
|
|
3 23 |
|
|
15 19 |
|
|
13 5 |
|
|
17 24 |
|
|
6 16 |
|
|
21 5 |
|
|
14 10 |
|
|
3 6 |
/*/
题意,跑跑车游戏,x方向速度为1,y方向自己控制范围在-1/r到1/r之间。 给出金币的坐标,最多问能捡到多少金币。 首先可以知道,我们的可以走的范围为由出发点引出的左右两条射线之内,如果下一个点在现在的点的射线范围内,那么这个金币可以被捡到。 如果没有在射线范围内,就无法被捡到 上图
可以从图中看到下面第一个绿色的点A可以直接走到的点有两个 B 和C,但是B只能再走向E,而C可以走到D,再从D走到E; 明显A-C-D-E这种路径长些,想到这里,我们可以这样去解决这个问题: 把每个点的坐标按照左右位移的速度 1/r 映射到左右两个边界,按照左右两个边界升序排序【左边界优先】,取右边界最大上升子序列就行了。 这里用到了一个迭代器upper_bound(a,a+n,x),它的作用是返回a数组中从x开始的递增序列的最后一个的地址。 AC代码:
/*/
#include"algorithm"
#include"iostream"
#include"cstring"
#include"cstdlib"
#include"cstdio"
#include"string"
#include"vector"
#include"queue"
#include"cmath"
using namespace std;
typedef long long LL ;
#define memset(x,y) memset(x,y,sizeof(x))
#define memcpy(x,y) memcpy(x,y,sizeof(x))
#define FK(x) cout<<"["<<x<<"]\n"
#define bigfor(x) for(LL qq=1;qq<= T ;qq++) const LL MX=1e5+5; struct Node {
LL x,y;
bool operator<(const Node &A)const {
return x < A.x;
}
void add(LL r,LL w,LL xx,LL yy) {
x=xx*r+yy;
y=(w-xx)*r+yy;
}
} nd[MX]; LL dp[MX]; int main() {
LL n,r,w,h,x,y;
while(~scanf("%I64d%I64d%I64d%I64d",&n,&r,&w,&h)) {
for(LL i=1; i<=n; i++) {
scanf("%I64d%I64d",&x,&y);
nd[i].add(r,w,x,y);
}
LL ans=0;
memset(dp,0x3f);
sort(nd+1,nd+1+n);
for(LL i=1; i<=n; i++) {
LL tem=upper_bound(dp+1,dp+1+n,nd[i].y)-&dp[0]; //★
ans = max(ans,tem);
dp[tem]=nd[i].y;
}
printf("%I64d",ans);
}
return 0;
} /*/
★升序排列的容器:
iterator lower_bound( const key_type &key ): 返回一个迭代器[地址],指向键值>= key的第一个元素。
iterator upper_bound( const key_type &key ):返回一个迭代器[地址],指向键值<=key的最后一个元素的后一个元素。
★降序排列的容器:
iterator lower_bound( const key_type &key ): 返回一个迭代器[地址],指向键值<= key的第一个元素。
iterator upper_bound( const key_type &key ):返回一个迭代器[地址],指向键值>=key的最后一个元素的后一个元素。
/*/
ACM: Racing Gems - 最长递增序列的更多相关文章
- POJ 2533 Longest Ordered Subsequence 最长递增序列
Description A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequenc ...
- uva103(最长递增序列,dag上的最长路)
题目的意思是给定k个盒子,每个盒子的维度有n dimension 问最多有多少个盒子能够依次嵌套 但是这个嵌套的规则有点特殊,两个盒子,D = (d1,d2,...dn) ,E = (e1,e2... ...
- [LeetCode] Number of Longest Increasing Subsequence 最长递增序列的个数
Given an unsorted array of integers, find the number of longest increasing subsequence. Example 1: I ...
- Leetcode 674.最长递增序列
最长递增序列 给定一个未经排序的整数数组,找到最长且连续的的递增序列. 示例 1: 输入: [1,3,5,4,7] 输出: 3 解释: 最长连续递增序列是 [1,3,5], 长度为3. 尽管 [1,3 ...
- [LeetCode] 673. Number of Longest Increasing Subsequence 最长递增序列的个数
Given an unsorted array of integers, find the number of longest increasing subsequence. Example 1: I ...
- XHXJ's LIS HDU - 4352 最长递增序列&数位dp
代码+题解: 1 //题意: 2 //输出在区间[li,ri]中有多少个数是满足这个要求的:这个数的最长递增序列长度等于k 3 //注意是最长序列,可不是子串.子序列是不用紧挨着的 4 // 5 // ...
- LeetCode OJ:Longest Increasing Subsequence(最长递增序列)
Given an unsorted array of integers, find the length of longest increasing subsequence. For example, ...
- [leetcode]最长递增序列
class Solution { public: int lengthOfLIS(vector<int>& nums) { int n=nums.size(); ) ; vecto ...
- 算法设计 - LCS 最长公共子序列&&最长公共子串 &&LIS 最长递增子序列
出处 http://segmentfault.com/blog/exploring/ 本章讲解:1. LCS(最长公共子序列)O(n^2)的时间复杂度,O(n^2)的空间复杂度:2. 与之类似但不同的 ...
随机推荐
- 缓慢变化维 (Slowly changing dimension)
维度建模的数据仓库中,有一个概念叫Slowly Changing Dimensions,中文一般翻译成"缓慢变化维",经常被简写为SCD.缓慢变化维的提出是因为在现实世 ...
- T-SQL 常用语句
1. 查看 Table 或者 Column 被那些object(存储过程.函数或View)调用. select a.* from sysobjects a, syscomments b where a ...
- IOS 100 - 1 开工闲聊
1 前言 现在的行情,作为码农,ios 普遍比c# 的待遇好上不少.感觉就如清洁工人,扫厕所干的再高效和干净,一个月就那么点微薄的收入.当然你可以选择去香港打扫卫生间,那里的行情据说清洁工也破万了.说 ...
- 人性的弱点&&影响力
How wo win friends and influence people 人性的弱点 by 卡耐基 人际关系基本技巧 不要批评.谴责.抱怨 真诚的欣赏他人 激发他人的渴望 获得别人好感的方式 微 ...
- Understanding Execution Governors and Limits
在编写Salesforce后台代码的时候,如果数据量比较大,或者需要与数据库的交互比较频繁的话,那么会抛出一些限制的异常,来提示你让你做进一步的修改. 有这些限制实质上是跟Salesforce是一个云 ...
- linux下java环境配置
非常简单的三行命令就搞定了! $ sudo add-apt-repository ppa:webupd8team/java$ sudo apt-get update$ sudo apt-get ins ...
- javase基础笔记4——异常/单例和类集框架
继承 extends final关键 多态 是在继承的基础上 接口 interface 异常 exception 包的访问可控制权限 private default protect public 异常 ...
- 长按事件jquery mobile
chat_enlarge.addEventListener('touchend', function(event) { if(fingers == 1){ event.preventDefault() ...
- Linux学习笔记(18) Shell编程之流程控制
1. if语句 (1) 单分支if条件语句 格式为: # 注意条件判断式两端的空格if [ 条件判断式 ];then 程序员 fi 或者 if[ 条件判断式 ] then 程序 fi 例:判断分区使用 ...
- 【java基础】选择排序and冒泡排序
前言 : 今天学习的是J2SE视频里的第五章,数组部分,它里面留了一个经典的作业,就是让我们去从1倒9按一定规格排序,这让我想起了学习vb的时候最最让我头疼的两种排序方法,选择排序法 和 冒泡排序法. ...
